Skip to content

Commit 3c22533

Browse files
committed
chore: sync config/*.go and values.schema.json to vCluster version v0.27.0-rc.1
1 parent 76a8e63 commit 3c22533

File tree

246 files changed

+412
-55967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+412
-55967
lines changed

config/config.go

Lines changed: 108 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/invopop/jsonschema"
15+
yamlv3 "gopkg.in/yaml.v3"
1516
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617
"k8s.io/apimachinery/pkg/labels"
1718
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -173,6 +174,10 @@ type Standalone struct {
173174
// Enabled defines if standalone mode should be enabled.
174175
Enabled bool `json:"enabled,omitempty"`
175176

177+
// SyncConfig allows controlling the vCluster config through a secret "vcluster-config" in the namespace "kube-system". vCluster will watch for changes in this secret and
178+
// update the local config accordingly and restart vCluster if needed.
179+
SyncConfig StandaloneSyncConfig `json:"syncConfig,omitempty"`
180+
176181
// DataDir defines the data directory for the standalone mode.
177182
DataDir string `json:"dataDir,omitempty"`
178183

@@ -186,13 +191,15 @@ type Standalone struct {
186191
JoinNode StandaloneJoinNode `json:"joinNode,omitempty"`
187192
}
188193

194+
type StandaloneSyncConfig struct {
195+
// Enabled defines if config syncing should be enabled.
196+
Enabled bool `json:"enabled,omitempty"`
197+
}
198+
189199
type StandaloneJoinNode struct {
190200
// Enabled defines if the standalone node should be joined into the cluster. If false, only the control plane binaries will be executed and no node will show up in the actual cluster.
191201
Enabled bool `json:"enabled,omitempty"`
192202

193-
// Name defines the name of the standalone node. If empty the node will get the hostname as name.
194-
Name string `json:"name,omitempty"`
195-
196203
JoinConfiguration `json:",inline"`
197204
}
198205

@@ -376,8 +383,9 @@ type AutoUpgrade struct {
376383
}
377384

378385
type Kubelet struct {
379-
// CgroupDriver defines the cgroup driver to use for the kubelet.
380-
CgroupDriver string `json:"cgroupDriver,omitempty"`
386+
// Config is the config for the kubelet that will be merged into the default kubelet config. More information can be found here:
387+
// https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/#kubelet-config-k8s-io-v1beta1-KubeletConfiguration
388+
Config map[string]interface{} `json:"config,omitempty"`
381389
}
382390

383391
type KubeProxy struct {
@@ -404,6 +412,10 @@ type KubeProxy struct {
404412

405413
// ExtraArgs are additional arguments to pass to the kube-proxy.
406414
ExtraArgs []string `json:"extraArgs,omitempty"`
415+
416+
// Config is the config for the kube-proxy that will be merged into the default kube-proxy config. More information can be found here:
417+
// https://kubernetes.io/docs/reference/config-api/kube-proxy-config.v1alpha1/#kubeproxy-config-k8s-io-v1alpha1-KubeProxyConfiguration
418+
Config map[string]interface{} `json:"config,omitempty"`
407419
}
408420

409421
type Konnectivity struct {
@@ -534,11 +546,17 @@ type ExternalSecrets struct {
534546
}
535547

536548
type ExternalSecretsSync struct {
549+
// ToHost defines what resources are synced from the virtual cluster to the host
550+
ToHost ExternalSecretsSyncToHostConfig `json:"toHost,omitempty"`
551+
// FromHost defines what resources are synced from the host cluster to the virtual cluster
552+
FromHost ExternalSecretsSyncFromHostConfig `json:"fromHost,omitempty"`
537553
// ExternalSecrets defines if external secrets should get synced from the virtual cluster to the host cluster.
538554
ExternalSecrets EnableSwitch `json:"externalSecrets,omitempty"`
539555
// Stores defines if secret stores should get synced from the virtual cluster to the host cluster and then bi-directionally.
556+
// Deprecated: Use Integrations.ExternalSecrets.Sync.ToHost.Stores instead.
540557
Stores EnableSwitch `json:"stores,omitempty"`
541558
// ClusterStores defines if cluster secrets stores should get synced from the host cluster to the virtual cluster.
559+
// Deprecated: Use Integrations.ExternalSecrets.Sync.FromHost.ClusterStores instead.
542560
ClusterStores ClusterStoresSyncConfig `json:"clusterStores,omitempty"`
543561
}
544562

@@ -548,6 +566,27 @@ type ClusterStoresSyncConfig struct {
548566
Selector LabelSelector `json:"selector,omitempty"`
549567
}
550568

569+
type ExternalSecretsSyncToHostConfig struct {
570+
// ExternalSecrets allows to configure if only a subset of ExternalSecrets matching a label selector should get synced from the virtual cluster to the host cluster.
571+
ExternalSecrets SelectorConfig `json:"externalSecrets,omitempty"`
572+
// Stores defines if secret stores should get synced from the virtual cluster to the host cluster and then bi-directionally.
573+
Stores EnableSwitchSelector `json:"stores,omitempty"`
574+
}
575+
576+
type ExternalSecretsSyncFromHostConfig struct {
577+
// ClusterStores defines if cluster secrets stores should get synced from the host cluster to the virtual cluster.
578+
ClusterStores EnableSwitchSelector `json:"clusterStores,omitempty"`
579+
}
580+
581+
type SelectorConfig struct {
582+
Selector StandardLabelSelector `json:"selector,omitempty"`
583+
}
584+
585+
type EnableSwitchSelector struct {
586+
SelectorConfig
587+
EnableSwitch
588+
}
589+
551590
type LabelSelector struct {
552591
// Labels defines what labels should be looked for
553592
Labels map[string]string `json:"labels,omitempty"`
@@ -835,6 +874,10 @@ func (c *Config) IsProFeatureEnabled() bool {
835874
return true
836875
}
837876

877+
if c.PrivateNodes.Enabled {
878+
return true
879+
}
880+
838881
return false
839882
}
840883

@@ -1278,7 +1321,7 @@ type SyncRewriteHosts struct {
12781321

12791322
type SyncRewriteHostsInitContainer struct {
12801323
// Image is the image virtual cluster should use to rewrite this FQDN.
1281-
Image string `json:"image,omitempty"`
1324+
Image Image `json:"image,omitempty"`
12821325

12831326
// Resources are the resources that should be assigned to the init container for each stateful set init container.
12841327
Resources Resources `json:"resources,omitempty"`
@@ -1572,7 +1615,9 @@ type ControlPlaneStatefulSet struct {
15721615
Pods LabelsAndAnnotations `json:"pods,omitempty"`
15731616

15741617
// Image is the image for the controlPlane statefulSet container
1575-
Image StatefulSetImage `json:"image,omitempty"`
1618+
// It defaults to the vCluster pro repository that includes the optional pro modules that are turned off by default.
1619+
// If you still want to use the pure OSS build, set the repository to 'loft-sh/vcluster-oss'.
1620+
Image Image `json:"image,omitempty"`
15761621

15771622
// ImagePullPolicy is the policy how to pull the image.
15781623
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
@@ -1629,7 +1674,7 @@ type DistroK8s struct {
16291674
// ControllerManager holds configuration specific to starting the controller manager.
16301675
ControllerManager DistroContainerEnabled `json:"controllerManager,omitempty"`
16311676

1632-
// Scheduler holds configuration specific to starting the scheduler. Enable this via controlPlane.advanced.virtualScheduler.enabled
1677+
// Scheduler holds configuration specific to starting the scheduler.
16331678
Scheduler DistroContainerEnabled `json:"scheduler,omitempty"`
16341679

16351680
DistroCommon `json:",inline"`
@@ -1670,20 +1715,6 @@ type DistroContainerEnabled struct {
16701715
ExtraArgs []string `json:"extraArgs,omitempty"`
16711716
}
16721717

1673-
type StatefulSetImage struct {
1674-
// Configure the registry of the container image, e.g. my-registry.com or ghcr.io
1675-
// It defaults to ghcr.io and can be overriding either by using this field or controlPlane.advanced.defaultImageRegistry
1676-
Registry string `json:"registry,omitempty"`
1677-
1678-
// Configure the repository of the container image, e.g. my-repo/my-image.
1679-
// It defaults to the vCluster pro repository that includes the optional pro modules that are turned off by default.
1680-
// If you still want to use the pure OSS build, use 'loft-sh/vcluster-oss' instead.
1681-
Repository string `json:"repository,omitempty"`
1682-
1683-
// Tag is the tag of the container image, e.g. latest
1684-
Tag string `json:"tag,omitempty"`
1685-
}
1686-
16871718
type Image struct {
16881719
// Registry is the registry of the container image, e.g. my-registry.com or ghcr.io. This setting can be globally
16891720
// overridden via the controlPlane.advanced.defaultImageRegistry option. Empty means docker hub.
@@ -1692,10 +1723,64 @@ type Image struct {
16921723
// Repository is the repository of the container image, e.g. my-repo/my-image
16931724
Repository string `json:"repository,omitempty"`
16941725

1695-
// Tag is the tag of the container image, e.g. latest. If set to the default, it will use the host Kubernetes version.
1726+
// Tag is the tag of the container image, and is the default version.
16961727
Tag string `json:"tag,omitempty"`
16971728
}
16981729

1730+
// UnmarshalJSON makes the schema change from string to Image backwards compatible
1731+
func (i *Image) UnmarshalJSON(data []byte) error {
1732+
var str string
1733+
if err := json.Unmarshal(data, &str); err == nil {
1734+
ParseImageRef(str, i)
1735+
return nil
1736+
}
1737+
1738+
type Alias Image
1739+
var aux Alias
1740+
if err := json.Unmarshal(data, &aux); err != nil {
1741+
return err
1742+
}
1743+
*i = Image(aux)
1744+
return nil
1745+
}
1746+
1747+
// UnmarshalYAML makes the schema change from string to Image backwards compatible
1748+
func (i *Image) UnmarshalYAML(node *yamlv3.Node) error {
1749+
if node.Kind == yamlv3.ScalarNode {
1750+
ParseImageRef(node.Value, i)
1751+
return nil
1752+
}
1753+
1754+
type Alias Image
1755+
var aux Alias
1756+
if err := node.Decode(&aux); err != nil {
1757+
return err
1758+
}
1759+
*i = Image(aux)
1760+
return nil
1761+
}
1762+
1763+
func (i *Image) String() (ref string) {
1764+
if i == nil {
1765+
return
1766+
}
1767+
1768+
if i.Registry != "" {
1769+
ref = i.Registry + "/"
1770+
}
1771+
1772+
if i.Registry != "" && i.Repository != "" && !strings.ContainsRune(i.Repository, '/') {
1773+
ref += "library/"
1774+
}
1775+
ref += i.Repository
1776+
1777+
if i.Tag != "" {
1778+
ref += ":" + i.Tag
1779+
}
1780+
1781+
return ref
1782+
}
1783+
16991784
type ImagePullSecretName struct {
17001785
// Name of the image pull secret to use.
17011786
Name string `json:"name,omitempty"`

config/config_test.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"testing"
77

88
"gotest.tools/assert"
9+
"gotest.tools/assert/cmp"
10+
"sigs.k8s.io/yaml"
911
)
1012

1113
func TestConfig_Diff(t *testing.T) {
@@ -385,3 +387,129 @@ func TestConfig_IsProFeatureEnabled(t *testing.T) {
385387
})
386388
}
387389
}
390+
391+
// We changed sync.toHost.pods.rewriteHosts.initContainer.image from a string to an object in 0.27.0.
392+
// We parse the previously used config on upgrade, so it must be backwards compatible.
393+
func TestImage_UnmarshalYAML(t *testing.T) {
394+
tests := []struct {
395+
name string
396+
yaml string
397+
expected Image
398+
}{
399+
{
400+
name: "image as object",
401+
yaml: `registry: registry:5000
402+
repository: some/repo
403+
tag: sometag`,
404+
expected: Image{
405+
Registry: "registry:5000",
406+
Repository: "some/repo",
407+
Tag: "sometag",
408+
},
409+
},
410+
{
411+
name: "image as string",
412+
yaml: "registry:5000/some/repo:sometag",
413+
expected: Image{
414+
Registry: "registry:5000",
415+
Repository: "some/repo",
416+
Tag: "sometag",
417+
},
418+
},
419+
}
420+
421+
for _, tt := range tests {
422+
t.Run(tt.name, func(t *testing.T) {
423+
var actual Image
424+
err := yaml.Unmarshal([]byte(tt.yaml), &actual)
425+
assert.NilError(t, err)
426+
assert.DeepEqual(t, actual, tt.expected)
427+
})
428+
}
429+
}
430+
431+
func TestImage_String(t *testing.T) {
432+
testCases := []struct {
433+
name string
434+
image Image
435+
expected string
436+
}{
437+
{
438+
name: "complete image reference",
439+
image: Image{
440+
Registry: "registry.k8s.io",
441+
Repository: "coredns/coredns",
442+
Tag: "1.11.3",
443+
},
444+
expected: "registry.k8s.io/coredns/coredns:1.11.3",
445+
},
446+
{
447+
name: "may omit registry",
448+
image: Image{
449+
Repository: "coredns/coredns",
450+
Tag: "1.11.3",
451+
},
452+
expected: "coredns/coredns:1.11.3",
453+
},
454+
{
455+
name: "may omit registry and repo",
456+
image: Image{
457+
Repository: "alpine",
458+
Tag: "3.20",
459+
},
460+
expected: "alpine:3.20",
461+
},
462+
{
463+
name: "may omit tag",
464+
image: Image{
465+
Repository: "alpine",
466+
},
467+
expected: "alpine",
468+
},
469+
{
470+
name: "omit repo but not registry is library",
471+
image: Image{
472+
Registry: "ghcr.io",
473+
Repository: "alpine",
474+
Tag: "3.20",
475+
},
476+
expected: "ghcr.io/library/alpine:3.20",
477+
},
478+
{
479+
name: "registry may have port",
480+
image: Image{
481+
Registry: "host.docker.internal:5000",
482+
Repository: "coredns/coredns",
483+
Tag: "1.11.3",
484+
},
485+
expected: "host.docker.internal:5000/coredns/coredns:1.11.3",
486+
},
487+
{
488+
name: "registry with port and omit tag",
489+
image: Image{
490+
Registry: "localhost:5000",
491+
Repository: "coredns/coredns",
492+
},
493+
expected: "localhost:5000/coredns/coredns",
494+
},
495+
{
496+
name: "empty image is nil value",
497+
image: Image{},
498+
expected: "",
499+
},
500+
}
501+
502+
for _, tt := range testCases {
503+
t.Run("String(): "+tt.name, func(t *testing.T) {
504+
if actual := tt.image.String(); actual != tt.expected {
505+
t.Errorf("Expected %s, got %s", tt.expected, actual)
506+
}
507+
})
508+
509+
t.Run("ParseImageRef(): "+tt.name, func(t *testing.T) {
510+
var image Image
511+
ParseImageRef(tt.expected, &image)
512+
assert.Check(t, cmp.DeepEqual(tt.image, image))
513+
})
514+
}
515+
}

0 commit comments

Comments
 (0)