Skip to content

Commit

Permalink
refactor: use config everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Mar 11, 2024
1 parent 919aa39 commit ddce771
Show file tree
Hide file tree
Showing 49 changed files with 1,004 additions and 1,142 deletions.
25 changes: 24 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ controlPlane:
distro:
k3s:
enabled: false
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "rancher/k3s"
Expand All @@ -83,6 +85,9 @@ controlPlane:

k0s:
enabled: false
config: ""
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "k0sproject/k0s"
Expand All @@ -100,17 +105,23 @@ controlPlane:
enabled: false
apiServer:
disabled: false
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "registry.k8s.io/kube-apiserver"
tag: "v1.29.0"
controllerManager:
disabled: false
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "registry.k8s.io/kube-controller-manager"
tag: "v1.29.0"
scheduler:
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "registry.k8s.io/kube-scheduler"
Expand All @@ -129,17 +140,23 @@ controlPlane:
enabled: false
apiServer:
disabled: false
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "public.ecr.aws/eks-distro/kubernetes/kube-apiserver"
tag: "v1.28.2-eks-1-28-6"
controllerManager:
disabled: false
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "public.ecr.aws/eks-distro/kubernetes/kube-controller-manager"
tag: "v1.28.2-eks-1-28-6"
scheduler:
command: []
extraArgs: []
imagePullPolicy: ""
image:
repository: "public.ecr.aws/eks-distro/kubernetes/kube-scheduler"
Expand Down Expand Up @@ -365,6 +382,9 @@ networking:
advanced:
clusterDomain: "cluster.local"
fallbackHostCluster: true
proxyKubelets:
byHostname: true
byIP: true

policies:
resourceQuota:
Expand All @@ -389,7 +409,7 @@ policies:
count/persistentvolumeclaims: 20
scopeSelector:
matchExpressions: []
scopes: {}
scopes: []

limitRange:
enabled: false
Expand Down Expand Up @@ -436,7 +456,10 @@ experimental:
enabled: false

syncSettings:
disableSync: false
rewriteKubernetesService: false
targetNamespace: ""
setOwner: true

isolatedControlPlane:
headless: false
Expand Down
15 changes: 6 additions & 9 deletions cmd/vcluster/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewStartCommand() *cobra.Command {
}()

// parse vCluster config
vClusterConfig, err := config.ParseConfig(startOptions.Config)
vClusterConfig, err := config.ParseConfig(startOptions.Config, os.Getenv("VCLUSTER_NAME"))
if err != nil {
return err
}
Expand All @@ -69,6 +69,9 @@ func ExecuteStart(ctx context.Context, vConfig *config.VirtualClusterConfig) err
if vConfig.ServiceName == "" {
vConfig.ServiceName = translate.VClusterName
}
if vConfig.ControlPlane.Advanced.WorkloadServiceAccount.Name == "" {
vConfig.ControlPlane.Advanced.WorkloadServiceAccount.Name = "vc-workload-" + vConfig.Name
}

// get current namespace
controlPlaneConfig, controlPlaneNamespace, controlPlaneService, workloadConfig, workloadNamespace, workloadService, err := pro.GetRemoteClient(vConfig)
Expand All @@ -94,10 +97,6 @@ func ExecuteStart(ctx context.Context, vConfig *config.VirtualClusterConfig) err
plugin.DefaultManager.SetProFeatures(pro.LicenseFeatures())

// get host cluster config and tweak rate-limiting configuration
workloadClient, err := kubernetes.NewForConfig(workloadConfig)
if err != nil {
return err
}
controlPlaneClient, err := kubernetes.NewForConfig(controlPlaneConfig)
if err != nil {
return err
Expand All @@ -106,12 +105,10 @@ func ExecuteStart(ctx context.Context, vConfig *config.VirtualClusterConfig) err
// check if we should create certs
err = setup.Initialize(
ctx,
workloadClient,
controlPlaneClient,
workloadNamespace,
controlPlaneNamespace,
translate.VClusterName,
options,
vConfig,
)
if err != nil {
return fmt.Errorf("initialize: %w", err)
Expand All @@ -120,7 +117,7 @@ func ExecuteStart(ctx context.Context, vConfig *config.VirtualClusterConfig) err
// build controller context
controllerCtx, err := setup.NewControllerContext(
ctx,
options,
vConfig,
workloadNamespace,
workloadConfig,
scheme.Scheme,
Expand Down
99 changes: 49 additions & 50 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import "regexp"

type Config struct {
ExportKubeConfig ExportKubeConfig `json:"exportKubeConfig,omitempty"`
ControlPlane ControlPlane `json:"controlPlane,omitempty"`
Sync Sync `json:"sync,omitempty"`
Observability Observability `json:"observability,omitempty"`
Networking Networking `json:"networking,omitempty"`
Plugin map[string]Plugin `json:"plugin,omitempty"`
Plugins map[string]Plugins `json:"plugins,omitempty"`
ControlPlane ControlPlane `json:"controlPlane,omitempty"`
Policies Policies `json:"policies,omitempty"`
RBAC RBAC `json:"rbac,omitempty"`

// Telemetry is the configuration related to telemetry gathered about vcluster usage.
Telemetry Telemetry `json:"telemetry,omitempty"`
Experimental Experimental `json:"experimental,omitempty"`
Platform Platform `json:"platform,omitempty"`

// legacy for compatibility
ServiceCIDR string `json:"serviceCIDR,omitempty"`
Pro bool `json:"pro,omitempty"`
}

type ExportKubeConfig struct {
Expand Down Expand Up @@ -79,11 +83,10 @@ type SyncAllResource struct {
type SyncPods struct {
Enabled bool `json:"enabled,omitempty"`

WorkloadServiceAccount string `json:"workloadServiceAccount,omitempty"`
TranslateImage map[string]string `json:"translateImage,omitempty"`
EnforceTolerations []string `json:"enforceTolerations,omitempty"` // validate format
UseSecretsForSATokens bool `json:"useSecretsForSATokens,omitempty"`
RewriteHosts SyncRewriteHosts `json:"rewriteHosts,omitempty"`
TranslateImage map[string]string `json:"translateImage,omitempty"`
EnforceTolerations []string `json:"enforceTolerations,omitempty"` // validate format
UseSecretsForSATokens bool `json:"useSecretsForSATokens,omitempty"`
RewriteHosts SyncRewriteHosts `json:"rewriteHosts,omitempty"`
}

type SyncRewriteHosts struct {
Expand Down Expand Up @@ -128,13 +131,13 @@ type MetricsProxy struct {

type Networking struct {
ReplicateServices ReplicateServices `json:"replicateServices,omitempty"`
ResolveServices ResolveServices `json:"resolveServices,omitempty"`
ResolveServices []ResolveServices `json:"resolveServices,omitempty"`
Advanced NetworkingAdvanced `json:"advanced,omitempty"`
}

type ReplicateServices struct {
ToHost ServiceMapping `json:"toHost,omitempty"`
FromHost ServiceMapping `json:"fromHost,omitempty"`
ToHost []ServiceMapping `json:"toHost,omitempty"`
FromHost []ServiceMapping `json:"fromHost,omitempty"`
}

type ServiceMapping struct {
Expand Down Expand Up @@ -255,37 +258,31 @@ type Distro struct {
K3S DistroK3s `json:"k3s,omitempty"`
K8S DistroK8s `json:"k8s,omitempty"`
K0S DistroK0s `json:"k0s,omitempty"`
EKS DistroEks `json:"eks,omitempty"`
EKS DistroK8s `json:"eks,omitempty"`
}

type DistroK3s struct {
Enabled bool `json:"enabled,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Token string `json:"token,omitempty"`
DistroCommon `json:",inline"`
DistroContainer `json:",inline"`
}

type DistroK8s struct {
Enabled bool `json:"enabled,omitempty"`
DistroCommon `json:",inline"`
APIServer DistroContainer `json:"apiServer,omitempty"`
ControllerManager DistroContainer `json:"controllerManager,omitempty"`
Scheduler DistroContainer `json:"scheduler,omitempty"`
APIServer DistroContainerDisabled `json:"apiServer,omitempty"`
ControllerManager DistroContainerDisabled `json:"controllerManager,omitempty"`
Scheduler DistroContainer `json:"scheduler,omitempty"`
}

type DistroK0s struct {
Enabled bool `json:"enabled,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Config string `json:"config,omitempty"`
DistroCommon `json:",inline"`
DistroContainer `json:",inline"`
}

type DistroEks struct {
Enabled bool `json:"enabled,omitempty"`
DistroCommon `json:",inline"`
APIServer DistroContainer `json:"apiServer,omitempty"`
ControllerManager DistroContainer `json:"controllerManager,omitempty"`
Scheduler DistroContainer `json:"scheduler,omitempty"`
}

type DistroCommon struct {
Env []map[string]interface{} `json:"env,omitempty"`
SecurityContext map[string]interface{} `json:"securityContext,omitempty"`
Expand All @@ -296,7 +293,14 @@ type DistroContainer struct {
Image Image `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
ExtraArgs []string `json:"extraArgs,omitempty"`
}

type DistroContainerDisabled struct {
Disabled bool `json:"disabled,omitempty"`
Image Image `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
Command []string `json:"command,omitempty"`
ExtraArgs []string `json:"extraArgs,omitempty"`
}

Expand Down Expand Up @@ -327,8 +331,8 @@ type BackingStore struct {
}

type EmbeddedEtcd struct {
Enabled bool `json:"enabled,omitempty"`
MigrateFromSqlite bool `json:"migrateFromSqlite,omitempty"`
Enabled bool `json:"enabled,omitempty"`
MigrateFromExternalEtcd bool `json:"migrateFromExternalEtcd,omitempty"`
}

type ExternalEtcd struct {
Expand All @@ -348,15 +352,15 @@ type ExternalEtcdMetadata struct {
}

type HostPathMapper struct {
EnableSwitch `json:",inline"`
Central bool `json:"central,omitempty" product:"pro"`
Enabled bool `json:"enabled,omitempty"`
Central bool `json:"central,omitempty" product:"pro"`
}

type CoreDNS struct {
EnableSwitch `json:",inline"`
Embedded bool `json:"embedded,omitempty" product:"pro"`
Service CoreDNSService `json:"service,omitempty"`
Deployment CoreDNSDeployment `json:"deployment,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Embedded bool `json:"embedded,omitempty" product:"pro"`
Service CoreDNSService `json:"service,omitempty"`
Deployment CoreDNSDeployment `json:"deployment,omitempty"`
}

type CoreDNSService struct {
Expand All @@ -370,13 +374,9 @@ type CoreDNSDeployment struct {
}

type ControlPlaneProxy struct {
BindAddress string `json:"bindAddress,omitempty"`
Port int `json:"port,omitempty"`
TLS ControlPlaneProxyTLS `json:"tls,omitempty"`
}

type ControlPlaneProxyTLS struct {
ExtraSANs []string `json:"extraSANs,omitempty"`
BindAddress string `json:"bindAddress,omitempty"`
Port int `json:"port,omitempty"`
ExtraSANs []string `json:"extraSANs,omitempty"`
}

type ControlPlaneService struct {
Expand Down Expand Up @@ -445,7 +445,7 @@ type VolumeMount struct {
type ControlPlaneScheduling struct {
NodeSelector map[string]interface{} `json:"nodeSelector,omitempty"`
Affinity map[string]interface{} `json:"affinity,omitempty"`
Tolerations map[string]interface{} `json:"tolerations,omitempty"`
Tolerations []interface{} `json:"tolerations,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
}

Expand Down Expand Up @@ -594,7 +594,6 @@ type Experimental struct {
Extended map[string]interface{} `json:",inline"`

IsolatedControlPlane ExperimentalIsolatedControlPlane `json:"isolatedControlPlane,omitempty"`
ControlPlaneSettings ExperimentalControlPlaneSettings `json:"controlPlaneSettings,omitempty"`
SyncSettings ExperimentalSyncSettings `json:"syncSettings,omitempty"`
GenericSync ExperimentalGenericSync `json:"genericSync,omitempty"`
Deploy ExperimentalDeploy `json:"deploy,omitempty"`
Expand All @@ -605,25 +604,25 @@ type Experimental struct {

type ExperimentalMultiNamespaceMode struct {
Enabled bool `json:"enabled,omitempty"`

NamespaceLabels map[string]string `json:"namespaceLabels,omitempty"`
}

type ExperimentalIsolatedControlPlane struct {
Enabled bool `json:"enabled,omitempty"`

KubeConfig string `json:"kubeConfig,omitempty"`
}

type ExperimentalControlPlaneSettings struct {
RewriteKubernetesService bool `json:"rewriteKubernetesService,omitempty"`
Namespace string `json:"namespace,omitempty"`
Service string `json:"service,omitempty"`
}

type ExperimentalSyncSettings struct {
DisableSync bool `json:"disableSync,omitempty"`
Target ExperimentalSyncSettingsTarget `json:"target,omitempty"`
}
DisableSync bool `json:"disableSync,omitempty"`
RewriteKubernetesService bool `json:"rewriteKubernetesService,omitempty"`

type ExperimentalSyncSettingsTarget struct {
Namespace string `json:"namespace,omitempty"`
TargetNamespace string `json:"targetNamespace,omitempty"`
SetOwner bool `json:"setOwner,omitempty"`
SyncLabels []string `json:"syncLabels,omitempty"`
}

type ExperimentalDeploy struct {
Expand Down
Loading

0 comments on commit ddce771

Please sign in to comment.