Skip to content

Commit

Permalink
Pass Bootstrap Features Configuration to the Cluster (#17)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Angelos Kolaitis <[email protected]>
  • Loading branch information
mateoflorido and neoaggelos authored Jul 4, 2024
1 parent 8e30e28 commit 7af836b
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 6 deletions.
65 changes: 64 additions & 1 deletion bootstrap/api/v1beta2/ck8sconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions bootstrap/api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions bootstrap/controllers/ck8sconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/ck8s/api/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 9 additions & 5 deletions pkg/ck8s/config_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
type InitControlPlaneConfig struct {
ControlPlaneEndpoint string
ControlPlaneConfig bootstrapv1.CK8sControlPlaneConfig
InitConfig bootstrapv1.CK8sInitConfiguration
PopulatedCertificates secret.Certificates

ClusterNetwork *clusterv1.ClusterNetwork
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7af836b

Please sign in to comment.