diff --git a/bootstrap/api/v1beta2/ck8sconfig_types.go b/bootstrap/api/v1beta2/ck8sconfig_types.go index 4e7467be..f04797e5 100644 --- a/bootstrap/api/v1beta2/ck8sconfig_types.go +++ b/bootstrap/api/v1beta2/ck8sconfig_types.go @@ -54,6 +54,10 @@ type CK8sConfigSpec struct { // CK8sControlPlaneConfig is configuration for the control plane node. // +optional ControlPlaneConfig CK8sControlPlaneConfig `json:"controlPlane,omitempty"` + + // CK8sInitConfig is configuration for the initializing the cluster features. + // +optional + InitConfig CK8sInitConfiguration `json:"initConfig,omitempty"` } // TODO @@ -62,7 +66,7 @@ func (c *CK8sConfigSpec) IsEtcdManaged() bool { return true } -// CK8sControlPlaneConfig is configuration for control plane noes. +// CK8sControlPlaneConfig is configuration for control plane nodes. type CK8sControlPlaneConfig struct { // ExtraSANs is a list of SANs to include in the server certificates. // +optional @@ -101,6 +105,65 @@ func (c *CK8sControlPlaneConfig) GetMicroclusterPort() int { return *c.MicroclusterPort } +// CK8sInitConfiguration is configuration for the initializing the cluster features. +type CK8sInitConfiguration struct { + // Annotations are used to configure the behaviour of the built-in features. + // +optional + Annotations map[string]string `json:"annotations,omitempty"` + + // EnableDefaultDNS specifies whether to enable the default DNS configuration. + // +optional + EnableDefaultDNS *bool `json:"enableDefaultDNS,omitempty"` + + // EnableDefaultLocalStorage specifies whether to enable the default local storage. + // +optional + EnableDefaultLocalStorage *bool `json:"enableDefaultLocalStorage,omitempty"` + + // EnableDefaultMetricsServer specifies whether to enable the default metrics server. + // +optional + EnableDefaultMetricsServer *bool `json:"enableDefaultMetricsServer,omitempty"` + + // EnableDefaultNetwork specifies whether to enable the default CNI. + // +optional + EnableDefaultNetwork *bool `json:"enableDefaultNetwork,omitempty"` +} + +// GetEnableDefaultNetwork returns the EnableDefaultNetwork field. +// If the field is not set, it returns true. +func (c *CK8sInitConfiguration) GetEnableDefaultDNS() bool { + if c.EnableDefaultDNS == nil { + return true + } + return *c.EnableDefaultDNS +} + +// GetEnableDefaultLocalStorage returns the EnableDefaultLocalStorage field. +// If the field is not set, it returns true. +func (c *CK8sInitConfiguration) GetEnableDefaultLocalStorage() bool { + if c.EnableDefaultLocalStorage == nil { + return true + } + return *c.EnableDefaultLocalStorage +} + +// GetEnableDefaultMetricsServer returns the EnableDefaultMetricsServer field. +// If the field is not set, it returns true. +func (c *CK8sInitConfiguration) GetEnableDefaultMetricsServer() bool { + if c.EnableDefaultMetricsServer == nil { + return true + } + return *c.EnableDefaultMetricsServer +} + +// GetEnableDefaultNetwork returns the EnableDefaultNetwork field. +// If the field is not set, it returns true. +func (c *CK8sInitConfiguration) GetEnableDefaultNetwork() bool { + if c.EnableDefaultNetwork == nil { + return true + } + return *c.EnableDefaultNetwork +} + // CK8sConfigStatus defines the observed state of CK8sConfig. type CK8sConfigStatus struct { // Ready indicates the BootstrapData field is ready to be consumed diff --git a/bootstrap/api/v1beta2/zz_generated.deepcopy.go b/bootstrap/api/v1beta2/zz_generated.deepcopy.go index c3c5217d..bf61cf62 100644 --- a/bootstrap/api/v1beta2/zz_generated.deepcopy.go +++ b/bootstrap/api/v1beta2/zz_generated.deepcopy.go @@ -110,6 +110,7 @@ func (in *CK8sConfigSpec) DeepCopyInto(out *CK8sConfigSpec) { copy(*out, *in) } in.ControlPlaneConfig.DeepCopyInto(&out.ControlPlaneConfig) + in.InitConfig.DeepCopyInto(&out.InitConfig) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CK8sConfigSpec. @@ -290,6 +291,48 @@ func (in *CK8sControlPlaneConfig) DeepCopy() *CK8sControlPlaneConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CK8sInitConfiguration) DeepCopyInto(out *CK8sInitConfiguration) { + *out = *in + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.EnableDefaultDNS != nil { + in, out := &in.EnableDefaultDNS, &out.EnableDefaultDNS + *out = new(bool) + **out = **in + } + if in.EnableDefaultLocalStorage != nil { + in, out := &in.EnableDefaultLocalStorage, &out.EnableDefaultLocalStorage + *out = new(bool) + **out = **in + } + if in.EnableDefaultMetricsServer != nil { + in, out := &in.EnableDefaultMetricsServer, &out.EnableDefaultMetricsServer + *out = new(bool) + **out = **in + } + if in.EnableDefaultNetwork != nil { + in, out := &in.EnableDefaultNetwork, &out.EnableDefaultNetwork + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CK8sInitConfiguration. +func (in *CK8sInitConfiguration) DeepCopy() *CK8sInitConfiguration { + if in == nil { + return nil + } + out := new(CK8sInitConfiguration) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *File) DeepCopyInto(out *File) { *out = *in diff --git a/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigs.yaml b/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigs.yaml index b81dac8d..c6d217cd 100644 --- a/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigs.yaml +++ b/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigs.yaml @@ -146,6 +146,33 @@ spec: - path type: object type: array + initConfig: + description: CK8sInitConfig is configuration for the initializing + the cluster features. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are used to configure the behaviour of + the built-in features. + type: object + enableDefaultDNS: + description: EnableDefaultDNS specifies whether to enable the + default DNS configuration. + type: boolean + enableDefaultLocalStorage: + description: EnableDefaultLocalStorage specifies whether to enable + the default local storage. + type: boolean + enableDefaultMetricsServer: + description: EnableDefaultMetricsServer specifies whether to enable + the default metrics server. + type: boolean + enableDefaultNetwork: + description: EnableDefaultNetwork specifies whether to enable + the default CNI. + type: boolean + type: object postRunCommands: description: PostRunCommands specifies extra commands to run in cloud-init after k8s-snap setup runs. diff --git a/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigtemplates.yaml b/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigtemplates.yaml index 11163237..29409ea3 100644 --- a/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigtemplates.yaml +++ b/bootstrap/config/crd/bases/bootstrap.cluster.x-k8s.io_ck8sconfigtemplates.yaml @@ -155,6 +155,33 @@ spec: - path type: object type: array + initConfig: + description: CK8sInitConfig is configuration for the initializing + the cluster features. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are used to configure the behaviour + of the built-in features. + type: object + enableDefaultDNS: + description: EnableDefaultDNS specifies whether to enable + the default DNS configuration. + type: boolean + enableDefaultLocalStorage: + description: EnableDefaultLocalStorage specifies whether + to enable the default local storage. + type: boolean + enableDefaultMetricsServer: + description: EnableDefaultMetricsServer specifies whether + to enable the default metrics server. + type: boolean + enableDefaultNetwork: + description: EnableDefaultNetwork specifies whether to + enable the default CNI. + type: boolean + type: object postRunCommands: description: PostRunCommands specifies extra commands to run in cloud-init after k8s-snap setup runs. diff --git a/bootstrap/controllers/ck8sconfig_controller.go b/bootstrap/controllers/ck8sconfig_controller.go index a56de6f6..f65a07f8 100644 --- a/bootstrap/controllers/ck8sconfig_controller.go +++ b/bootstrap/controllers/ck8sconfig_controller.go @@ -449,6 +449,7 @@ func (r *CK8sConfigReconciler) handleClusterNotInitialized(ctx context.Context, ControlPlaneEndpoint: scope.Cluster.Spec.ControlPlaneEndpoint.Host, ControlPlaneConfig: scope.Config.Spec.ControlPlaneConfig, PopulatedCertificates: certificates, + InitConfig: scope.Config.Spec.InitConfig, ClusterNetwork: scope.Cluster.Spec.ClusterNetwork, }) diff --git a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanes.yaml b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanes.yaml index 0f5a299e..6dac044d 100644 --- a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanes.yaml +++ b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanes.yaml @@ -343,6 +343,33 @@ spec: - path type: object type: array + initConfig: + description: CK8sInitConfig is configuration for the initializing + the cluster features. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are used to configure the behaviour + of the built-in features. + type: object + enableDefaultDNS: + description: EnableDefaultDNS specifies whether to enable + the default DNS configuration. + type: boolean + enableDefaultLocalStorage: + description: EnableDefaultLocalStorage specifies whether to + enable the default local storage. + type: boolean + enableDefaultMetricsServer: + description: EnableDefaultMetricsServer specifies whether + to enable the default metrics server. + type: boolean + enableDefaultNetwork: + description: EnableDefaultNetwork specifies whether to enable + the default CNI. + type: boolean + type: object postRunCommands: description: PostRunCommands specifies extra commands to run in cloud-init after k8s-snap setup runs. diff --git a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanetemplates.yaml b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanetemplates.yaml index 1f70361c..d868a732 100644 --- a/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanetemplates.yaml +++ b/controlplane/config/crd/bases/controlplane.cluster.x-k8s.io_ck8scontrolplanetemplates.yaml @@ -320,6 +320,33 @@ spec: - path type: object type: array + initConfig: + description: CK8sInitConfig is configuration for the initializing + the cluster features. + properties: + annotations: + additionalProperties: + type: string + description: Annotations are used to configure the + behaviour of the built-in features. + type: object + enableDefaultDNS: + description: EnableDefaultDNS specifies whether to + enable the default DNS configuration. + type: boolean + enableDefaultLocalStorage: + description: EnableDefaultLocalStorage specifies whether + to enable the default local storage. + type: boolean + enableDefaultMetricsServer: + description: EnableDefaultMetricsServer specifies + whether to enable the default metrics server. + type: boolean + enableDefaultNetwork: + description: EnableDefaultNetwork specifies whether + to enable the default CNI. + type: boolean + type: object postRunCommands: description: PostRunCommands specifies extra commands to run in cloud-init after k8s-snap setup runs. diff --git a/pkg/ck8s/api/cluster_config.go b/pkg/ck8s/api/cluster_config.go index e7dc44ac..3e26b1a3 100644 --- a/pkg/ck8s/api/cluster_config.go +++ b/pkg/ck8s/api/cluster_config.go @@ -9,6 +9,7 @@ type UserFacingClusterConfig struct { Gateway GatewayConfig `json:"gateway,omitempty" yaml:"gateway,omitempty"` MetricsServer MetricsServerConfig `json:"metrics-server,omitempty" yaml:"metrics-server,omitempty"` CloudProvider *string `json:"cloud-provider,omitempty" yaml:"cloud-provider,omitempty"` + Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"` } type DNSConfig struct { diff --git a/pkg/ck8s/config_init.go b/pkg/ck8s/config_init.go index 4d813713..78fc46de 100644 --- a/pkg/ck8s/config_init.go +++ b/pkg/ck8s/config_init.go @@ -15,6 +15,7 @@ import ( type InitControlPlaneConfig struct { ControlPlaneEndpoint string ControlPlaneConfig bootstrapv1.CK8sControlPlaneConfig + InitConfig bootstrapv1.CK8sInitConfiguration PopulatedCertificates secret.Certificates ClusterNetwork *clusterv1.ClusterNetwork @@ -55,11 +56,14 @@ func GenerateInitControlPlaneConfig(cfg InitControlPlaneConfig) (apiv1.Bootstrap out.ClusterConfig.CloudProvider = ptr.To(v) } - // TODO(neoaggelos): configurable components through the CK8sConfigTemplate - out.ClusterConfig.DNS.Enabled = ptr.To(true) - out.ClusterConfig.Network.Enabled = ptr.To(true) - out.ClusterConfig.MetricsServer.Enabled = ptr.To(true) - out.ClusterConfig.LocalStorage.Enabled = ptr.To(true) + // annotations + out.ClusterConfig.Annotations = cfg.InitConfig.Annotations + + // features + out.ClusterConfig.DNS.Enabled = ptr.To(cfg.InitConfig.GetEnableDefaultDNS()) + out.ClusterConfig.LocalStorage.Enabled = ptr.To(cfg.InitConfig.GetEnableDefaultLocalStorage()) + out.ClusterConfig.MetricsServer.Enabled = ptr.To(cfg.InitConfig.GetEnableDefaultMetricsServer()) + out.ClusterConfig.Network.Enabled = ptr.To(cfg.InitConfig.GetEnableDefaultNetwork()) // networking if cfg.ClusterNetwork != nil {