diff --git a/api/v1alpha1/aws_clusterconfig_types.go b/api/v1alpha1/aws_clusterconfig_types.go index 5f4274dcb..7bc73818f 100644 --- a/api/v1alpha1/aws_clusterconfig_types.go +++ b/api/v1alpha1/aws_clusterconfig_types.go @@ -4,6 +4,8 @@ package v1alpha1 import ( + "maps" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -24,17 +26,26 @@ type AWSClusterConfig struct { type AWSClusterConfigSpec struct { // +optional Region *Region `json:"region,omitempty"` + + GenericClusterConfig `json:",inline"` } func (AWSClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { + clusterConfigProps := GenericClusterConfig{}.VariableSchema().OpenAPIV3Schema.Properties + + maps.Copy( + clusterConfigProps, + map[string]clusterv1.JSONSchemaProps{ + "region": Region("").VariableSchema().OpenAPIV3Schema, + }, + ) + return clusterv1.VariableSchema{ OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS Cluster configuration", + Description: "AWS cluster configuration", Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "region": Region("").VariableSchema().OpenAPIV3Schema, - }, - Required: []string{"region"}, + Properties: clusterConfigProps, + Required: []string{"region"}, }, } } diff --git a/api/v1alpha1/clusterconfig_types.go b/api/v1alpha1/clusterconfig_types.go index c242f1e1c..b599706ba 100644 --- a/api/v1alpha1/clusterconfig_types.go +++ b/api/v1alpha1/clusterconfig_types.go @@ -4,7 +4,6 @@ package v1alpha1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables" @@ -15,18 +14,8 @@ const ( CNIProviderCalico = "calico" ) -//+kubebuilder:object:root=true - -// ClusterConfig is the Schema for the clusterconfigs API. -type ClusterConfig struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec ClusterConfigSpec `json:"spec,omitempty"` -} - -// ClusterConfigSpec defines the desired state of ClusterConfig. -type ClusterConfigSpec struct { +// GenericClusterConfig defines the generic cluster configdesired. +type GenericClusterConfig struct { // +optional KubernetesImageRepository *KubernetesImageRepository `json:"kubernetesImageRepository,omitempty"` @@ -43,7 +32,7 @@ type ClusterConfigSpec struct { Addons *Addons `json:"addons,omitempty"` } -func (ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { +func (GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { return clusterv1.VariableSchema{ OpenAPIV3Schema: clusterv1.JSONSchemaProps{ Description: "Cluster configuration", @@ -240,8 +229,3 @@ func (NFD) VariableSchema() clusterv1.VariableSchema { }, } } - -// +kubebuilder:object:root=true -func init() { - SchemeBuilder.Register(&ClusterConfig{}) -} diff --git a/api/v1alpha1/docker_clusterconfig_types.go b/api/v1alpha1/docker_clusterconfig_types.go new file mode 100644 index 000000000..82bb7fd08 --- /dev/null +++ b/api/v1alpha1/docker_clusterconfig_types.go @@ -0,0 +1,40 @@ +// Copyright 2023 D2iQ, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +//+kubebuilder:object:root=true + +// DockerClusterConfig is the Schema for the dockerclusterconfigs API. +type DockerClusterConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec AWSClusterConfigSpec `json:"spec,omitempty"` +} + +// DockerClusterConfigSpec defines the desired state of DockerClusterConfig. +type DockerClusterConfigSpec struct { + GenericClusterConfig `json:",inline"` +} + +func (DockerClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { + clusterConfigProps := GenericClusterConfig{}.VariableSchema().OpenAPIV3Schema.Properties + + return clusterv1.VariableSchema{ + OpenAPIV3Schema: clusterv1.JSONSchemaProps{ + Description: "Docker cluster configuration", + Type: "object", + Properties: clusterConfigProps, + }, + } +} + +func init() { + SchemeBuilder.Register(&DockerClusterConfig{}) +} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 52244b205..f1d55701c 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -45,6 +45,7 @@ func (in *AWSClusterConfigSpec) DeepCopyInto(out *AWSClusterConfigSpec) { *out = new(Region) **out = **in } + in.GenericClusterConfig.DeepCopyInto(&out.GenericClusterConfig) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSClusterConfigSpec. @@ -98,25 +99,25 @@ func (in *CNI) DeepCopy() *CNI { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterConfig) DeepCopyInto(out *ClusterConfig) { +func (in *DockerClusterConfig) DeepCopyInto(out *DockerClusterConfig) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfig. -func (in *ClusterConfig) DeepCopy() *ClusterConfig { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerClusterConfig. +func (in *DockerClusterConfig) DeepCopy() *DockerClusterConfig { if in == nil { return nil } - out := new(ClusterConfig) + out := new(DockerClusterConfig) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ClusterConfig) DeepCopyObject() runtime.Object { +func (in *DockerClusterConfig) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -124,41 +125,17 @@ func (in *ClusterConfig) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterConfigSpec) DeepCopyInto(out *ClusterConfigSpec) { +func (in *DockerClusterConfigSpec) DeepCopyInto(out *DockerClusterConfigSpec) { *out = *in - if in.KubernetesImageRepository != nil { - in, out := &in.KubernetesImageRepository, &out.KubernetesImageRepository - *out = new(KubernetesImageRepository) - **out = **in - } - if in.Etcd != nil { - in, out := &in.Etcd, &out.Etcd - *out = new(Etcd) - (*in).DeepCopyInto(*out) - } - if in.Proxy != nil { - in, out := &in.Proxy, &out.Proxy - *out = new(HTTPProxy) - (*in).DeepCopyInto(*out) - } - if in.ExtraAPIServerCertSANs != nil { - in, out := &in.ExtraAPIServerCertSANs, &out.ExtraAPIServerCertSANs - *out = make(ExtraAPIServerCertSANs, len(*in)) - copy(*out, *in) - } - if in.Addons != nil { - in, out := &in.Addons, &out.Addons - *out = new(Addons) - (*in).DeepCopyInto(*out) - } + in.GenericClusterConfig.DeepCopyInto(&out.GenericClusterConfig) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfigSpec. -func (in *ClusterConfigSpec) DeepCopy() *ClusterConfigSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerClusterConfigSpec. +func (in *DockerClusterConfigSpec) DeepCopy() *DockerClusterConfigSpec { if in == nil { return nil } - out := new(ClusterConfigSpec) + out := new(DockerClusterConfigSpec) in.DeepCopyInto(out) return out } @@ -202,6 +179,46 @@ func (in ExtraAPIServerCertSANs) DeepCopy() ExtraAPIServerCertSANs { return *out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GenericClusterConfig) DeepCopyInto(out *GenericClusterConfig) { + *out = *in + if in.KubernetesImageRepository != nil { + in, out := &in.KubernetesImageRepository, &out.KubernetesImageRepository + *out = new(KubernetesImageRepository) + **out = **in + } + if in.Etcd != nil { + in, out := &in.Etcd, &out.Etcd + *out = new(Etcd) + (*in).DeepCopyInto(*out) + } + if in.Proxy != nil { + in, out := &in.Proxy, &out.Proxy + *out = new(HTTPProxy) + (*in).DeepCopyInto(*out) + } + if in.ExtraAPIServerCertSANs != nil { + in, out := &in.ExtraAPIServerCertSANs, &out.ExtraAPIServerCertSANs + *out = make(ExtraAPIServerCertSANs, len(*in)) + copy(*out, *in) + } + if in.Addons != nil { + in, out := &in.Addons, &out.Addons + *out = new(Addons) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericClusterConfig. +func (in *GenericClusterConfig) DeepCopy() *GenericClusterConfig { + if in == nil { + return nil + } + out := new(GenericClusterConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HTTPProxy) DeepCopyInto(out *HTTPProxy) { *out = *in diff --git a/cmd/main.go b/cmd/main.go index 6854726c5..b7cafa8aa 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -29,7 +29,7 @@ import ( "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/server" awsclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig" "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/mutation/region" - genericclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig" + dockerclusterconfig "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/docker/clusterconfig" "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/lifecycle/cni/calico" "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/lifecycle/nfd" "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/lifecycle/servicelbgc" @@ -119,60 +119,49 @@ func main() { } // Handlers for lifecycle hooks. - genericLifeCycleHandlers := []handlers.Named{ + genericLifecycleHandlers := []handlers.Named{ + calico.New(mgr.GetClient(), calicoCNIConfig), + nfd.New(mgr.GetClient(), nfdConfig), servicelbgc.New(mgr.GetClient()), } - // Handlers that apply patches to the Cluster object and its objects. - // Used by CAPI's GeneratePatches hook. - genericPatchHandlers := []handlers.Named{ - httpproxy.NewPatch(mgr.GetClient()), - extraapiservercertsans.NewPatch(), - auditpolicy.NewPatch(), - kubernetesimagerepository.NewPatch(), - etcd.NewPatch(), - } - // Handlers used by CAPI's DiscoverVariables hook. - // It's ok that this does not match patchHandlers. - // Some of those handlers may always get applied and not have a corresponding variable. - genericVariableHandlers := []handlers.Named{ - httpproxy.NewVariable(), - extraapiservercertsans.NewVariable(), - kubernetesimagerepository.NewVariable(), - } + // This genericMetaPatchHandlers combines all other patch and variable handlers under a single handler. // It allows to specify configuration under a single variable. genericMetaPatchHandlers := []mutation.MetaMutater{ - httpproxy.NewMetaPatch(mgr.GetClient()), - extraapiservercertsans.NewMetaPatch(), auditpolicy.NewPatch(), - kubernetesimagerepository.NewMetaPatch(), etcd.NewMetaPatch(), - } - genericMetaHandlers := []handlers.Named{ - // This Calico handler relies on a variable but does not generate a patch. - // Instead it creates other resources in the API. - calico.NewMetaHandler(mgr.GetClient(), calicoCNIConfig), - nfd.NewMetaHandler(mgr.GetClient(), nfdConfig), - genericclusterconfig.NewVariable(), - mutation.NewMetaGeneratePatchesHandler("clusterConfigPatch", genericMetaPatchHandlers...), + extraapiservercertsans.NewMetaPatch(), + httpproxy.NewMetaPatch(mgr.GetClient()), + kubernetesimagerepository.NewMetaPatch(), } - // This awsMetaPatchHandlers combines all AWS patch and variable handlers under a single handler. + // awsMetaPatchHandlers combines all AWS patch and variable handlers under a single handler. // It allows to specify configuration under a single variable. - awsMetaPatchHandlers := []mutation.MetaMutater{ - region.NewMetaPatch(), - } + awsMetaPatchHandlers := append( + []mutation.MetaMutater{ + region.NewMetaPatch(), + }, + genericMetaPatchHandlers..., + ) awsMetaHandlers := []handlers.Named{ awsclusterconfig.NewVariable(), mutation.NewMetaGeneratePatchesHandler("awsClusterConfigPatch", awsMetaPatchHandlers...), } + // dockerMetaPatchHandlers combines all Docker patch and variable handlers under a single handler. + // It allows to specify configuration under a single variable. + dockerMetaPatchHandlers := []mutation.MetaMutater{} + dockerMetaHandlers := []handlers.Named{ + dockerclusterconfig.NewVariable(), + mutation.NewMetaGeneratePatchesHandler( + "dockerClusterConfigPatch", + dockerMetaPatchHandlers...), + } + var allHandlers []handlers.Named - allHandlers = append(allHandlers, genericLifeCycleHandlers...) - allHandlers = append(allHandlers, genericPatchHandlers...) - allHandlers = append(allHandlers, genericVariableHandlers...) - allHandlers = append(allHandlers, genericMetaHandlers...) + allHandlers = append(allHandlers, genericLifecycleHandlers...) allHandlers = append(allHandlers, awsMetaHandlers...) + allHandlers = append(allHandlers, dockerMetaHandlers...) runtimeWebhookServer := server.NewServer(runtimeWebhookServerOpts, allHandlers...) diff --git a/devbox.json b/devbox.json index a7322c86e..8700f883b 100644 --- a/devbox.json +++ b/devbox.json @@ -35,5 +35,12 @@ "yamale@latest", "yamllint@latest", "kind@latest" - ] + ], + "shell": { + "scripts": { + "preview-docs": [ + "cd docs && hugo serve -F -D" + ] + } + } } diff --git a/docs/archetypes/default.md b/docs/archetypes/default.md index fdccff8ae..c3a813651 100644 --- a/docs/archetypes/default.md +++ b/docs/archetypes/default.md @@ -1,4 +1,3 @@ ---- -title: "{{ replace .Name "-" " " | title }}" -date: {{ .Date }} ---- ++++ +title = "{{ replace .Name "-" " " | title }}" ++++ diff --git a/docs/content/_index.md b/docs/content/_index.md index 43ead1a6f..d77a355c9 100644 --- a/docs/content/_index.md +++ b/docs/content/_index.md @@ -1,12 +1,12 @@ +++ title = "CAPI Runtime Extensions" -[[cascade]] -type = "blog" -toc_root = true +# [[cascade]] +# type = "blog" +# toc_root = true - [cascade._target] - path = "/news/**" +# [cascade._target] +# path = "/blog/**" [[cascade]] type = "docs" diff --git a/docs/content/addons/_index.md b/docs/content/addons/_index.md new file mode 100644 index 000000000..1760a7d35 --- /dev/null +++ b/docs/content/addons/_index.md @@ -0,0 +1,3 @@ ++++ +title = "Addons" ++++ diff --git a/docs/content/calico-cni.md b/docs/content/addons/calico-cni.md similarity index 68% rename from docs/content/calico-cni.md rename to docs/content/addons/calico-cni.md index e42038df7..0728317ef 100644 --- a/docs/content/calico-cni.md +++ b/docs/content/addons/calico-cni.md @@ -1,33 +1,20 @@ ---- -title: "Calico CNI" ---- ++++ +title = "Calico CNI" ++++ When deploying a cluster with CAPI, deployment and configuration of CNI is up to the user. By leveraging CAPI cluster lifecycle hooks, this handler deploys Calico CNI on the new cluster via `ClusterResourceSets` at the `AfterControlPlaneInitialized` phase. -Deployment of Calico is opt-in using the following configuration for the lifecycle hook to perform any actions. +Deployment of Calico is opt-in via the [provider-specific cluster configuration]({{< ref ".." >}}). + The hook creates two `ClusterResourceSets`: one to deploy the Tigera Operator, and one to deploy Calico via the Tigera `Installation` CRD. The Tigera Operator CRS is shared between all clusters in the operator, whereas the Calico installation CRS is unique per cluster. -To enable the meta handler enable the `clusterconfigvars` and `clusterconfigpatch` -external patches on `ClusterClass`. - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: -spec: - patches: - - name: cluster-config - external: - generateExtension: "clusterconfigpatch.capi-runtime-extensions" - discoverVariablesExtension: "clusterconfigvars.capi-runtime-extensions" -``` +## Example -On the cluster resource then specify this `cni` value: +To enable deployment of Calico on a cluster, specify the following values: ```yaml apiVersion: cluster.x-k8s.io/v1beta1 diff --git a/docs/content/addons/nfd.md b/docs/content/addons/nfd.md new file mode 100644 index 000000000..cfcb9b51e --- /dev/null +++ b/docs/content/addons/nfd.md @@ -0,0 +1,29 @@ ++++ +title = "Node Feature Discovery" ++++ + +By leveraging CAPI cluster lifecycle hooks, this handler deploys [Node Feature +Discovery](https://github.com/kubernetes-sigs/node-feature-discovery) (NFD) on the new cluster via `ClusterResourceSets` +at the `AfterControlPlaneInitialized` phase. + +Deployment of NFD is opt-in via the [provider-specific cluster configuration]({{< ref ".." >}}). + +The hook creates a `ClusterResourceSet` to deploy the NFD resources. + +## Example + +To enable deployment of NFD on a cluster, specify the following values: + +```yaml +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: +spec: + topology: + variables: + - name: clusterConfig + value: + addons: + nfd: {} +``` diff --git a/docs/content/audit-policy.md b/docs/content/audit-policy.md deleted file mode 100644 index 408e36d71..000000000 --- a/docs/content/audit-policy.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: "Audit policy" ---- - -Kubernetes auditing provides a security-relevant, chronological set of records documenting the sequence of actions in a -cluster. The cluster audits the activities generated by users, by applications that use the Kubernetes API, and by the -control plane itself. The `auditpolicypatch` external patch will generate appropriate configuration for the Kubernetes -control plane. - -To enable the audit policy enable the `auditpolicypatch` external patch on `ClusterClass`. - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: -spec: - patches: - - name: audit-policy - external: - generateExtension: "auditpolicypatch.capi-runtime-extensions" -``` - -Applying this configuration will result in new bootstrap files on the `KubeadmControlPlaneTemplate`. diff --git a/docs/content/cluster-config.md b/docs/content/customization/_index.md similarity index 96% rename from docs/content/cluster-config.md rename to docs/content/customization/_index.md index a400b10ef..188dba5ec 100644 --- a/docs/content/cluster-config.md +++ b/docs/content/customization/_index.md @@ -1,6 +1,7 @@ ---- -title: "Cluster Config" ---- ++++ +title = "Cluster customizations" +weight = 1 ++++ The Cluster Config handlers wrap all the other mutation handlers in a convenient single patch for inclusion in your ClusterClasses, allowing for a single configuration variable with nested values. This provides the most flexibility diff --git a/docs/content/customization/aws/_index.md b/docs/content/customization/aws/_index.md new file mode 100644 index 000000000..dd0d88f88 --- /dev/null +++ b/docs/content/customization/aws/_index.md @@ -0,0 +1,6 @@ ++++ +title = "AWS" ++++ + +The customizations in this section are applicable only to AWS clusters. They will only be applied to clusters that +use the `AWS` infrastructure provider, i.e. a CAPI `Cluster` that references an `AWSCluster`. diff --git a/docs/content/customization/aws/region.md b/docs/content/customization/aws/region.md new file mode 100644 index 000000000..9d8b3e1c6 --- /dev/null +++ b/docs/content/customization/aws/region.md @@ -0,0 +1,36 @@ ++++ +title = "Region" ++++ + +The region customization allows the user to specify the region to deploy a cluster into. + +This customization will be available when the +[provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`. + +## Example + +To specify the AWS region to deploy into, use the following configuration: + +```yaml +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: +spec: + topology: + variables: + - name: clusterConfig + values: + region: us-west-2 +``` + +Applying this configuration will result in the following value being set: + +- `AWSClusterTemplate`: + + - ```yaml + spec: + template: + spec: + region: us-west-2 + ``` diff --git a/docs/content/customization/generic/_index.md b/docs/content/customization/generic/_index.md new file mode 100644 index 000000000..0b93a1171 --- /dev/null +++ b/docs/content/customization/generic/_index.md @@ -0,0 +1,6 @@ ++++ +title = "Generic" +weight = 1 ++++ + +The customizations in this section are applicable to all providers. diff --git a/docs/content/customization/generic/audit-policy.md b/docs/content/customization/generic/audit-policy.md new file mode 100644 index 000000000..98791515d --- /dev/null +++ b/docs/content/customization/generic/audit-policy.md @@ -0,0 +1,11 @@ ++++ +title = "Audit policy" ++++ + +Kubernetes auditing provides a security-relevant, chronological set of records documenting the sequence of actions in a +cluster. The cluster audits the activities generated by users, by applications that use the Kubernetes API, and by the +control plane itself. + +There are currently no configuration options for the Audit Policy customization and this customization will be +automatically applied when the [provider-specific cluster configuration patch]({{< ref ".." >}}) is included in the +`ClusterClass`. diff --git a/docs/content/customization/generic/etcd.md b/docs/content/customization/generic/etcd.md new file mode 100644 index 000000000..f8b653184 --- /dev/null +++ b/docs/content/customization/generic/etcd.md @@ -0,0 +1,43 @@ ++++ +title = "etcd" ++++ + +This customization will be available when the +[provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`. + +The etcd configuration can then be manipulated via the cluster variables. If the `etcd` property is not specified, then +the customization will be skipped. + +## Example + +To change the repository and tag for the container image for the etcd pod, specify the following configuration: + +```yaml +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: +spec: + topology: + variables: + - name: clusterConfig + values: + etcd: + image: + repository: my-registry.io/my-org/my-repo + tag: "v3.5.99_custom.0" +``` + +Applying this configuration will result in the following value being set: + +- `KubeadmControlPlaneTemplate`: + + - ```yaml + spec: + kubeadmConfigSpec: + clusterConfiguration: + etcd: + local: + imageRepository: "my-registry.io/my-org/my-repo" + imageTag: "v3.5.99_custom.0" + ``` diff --git a/docs/content/customization/generic/extra-apiserver-cert-sans.md b/docs/content/customization/generic/extra-apiserver-cert-sans.md new file mode 100644 index 000000000..e8eea6f94 --- /dev/null +++ b/docs/content/customization/generic/extra-apiserver-cert-sans.md @@ -0,0 +1,41 @@ ++++ +title = "Extra API Server Certificate SANs" ++++ + +If the API server can be accessed by alternative DNS addresses then setting additional SANs on the API server +certificate is necessary in order for clients to successfully validate the API server certificate. + +This customization will be available when the +[provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`. + +## Example + +To add extra SANs to the API server certificate, specify the following configuration: + +```yaml +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: +spec: + topology: + variables: + - name: clusterConfig + value: + extraAPIServerCertSANs: + - a.b.c.example.com + - d.e.f.example.com +``` + +Applying this configuration will result in the following value being set: + +- `KubeadmControlPlaneTemplate`: + + - ```yaml + spec: + kubeadmConfigSpec: + clusterConfiguration: + apiServer: + certSANs: + - a.b.c.example.com + - d.e.f.example.com diff --git a/docs/content/customization/generic/http-proxy.md b/docs/content/customization/generic/http-proxy.md new file mode 100644 index 000000000..3288b6bf0 --- /dev/null +++ b/docs/content/customization/generic/http-proxy.md @@ -0,0 +1,65 @@ ++++ +title = "HTTP proxy" ++++ + +In some network environments it is necessary to use HTTP proxy to successfuly execute HTTP requests. +This customization will configure Kubernetes components (`containerd`, `kubelet`) with appropriate configuration for +control plane and worker nodes, utilising systemd drop-ins to configure the necessary environment variables. + +This customization will be available when the +[provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`. + +## Example + +To configure HTTP proxy values, specify the following configuration: + +```yaml +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: +spec: + topology: + variables: + - name: clusterConfig + value: + proxy: + http: http://example.com + https: http://example.com + additionalNo: + - no-proxy-1.example.com + - no-proxy-2.example.com +``` + +The `additionalNo` list will be added to default pre-calculated values that apply on k8s networking +`localhost,127.0.0.1,,,kubernetes,kubernetes.default,.svc,.svc.cluster.local`, plus +provider-specific addresses as required. + +Applying this configuration will result in the following value being set: + +- `KubeadmControlPlaneTemplate`: + + - ```yaml + spec: + kubeadmConfigSpec: + clusterConfiguration: + files: + - path: "/etc/systemd/system/containerd.service.d/http-proxy.conf" + content: + - path: "/etc/systemd/system/kubelet.service.d/http-proxy.conf" + content: + ``` + +- `KubeadmConfigTemplate`: + + - ```yaml + spec: + files: + - path: "/etc/systemd/system/containerd.service.d/http-proxy.conf" + content: + - path: "/etc/systemd/system/kubelet.service.d/http-proxy.conf" + content: + ``` + +Applying this configuration will result in new bootstrap files on the `KubeadmControlPlaneTemplate` +and `KubeadmConfigTemplate`. diff --git a/docs/content/customization/generic/kubernetes-image-repository.md b/docs/content/customization/generic/kubernetes-image-repository.md new file mode 100644 index 000000000..5386f3d58 --- /dev/null +++ b/docs/content/customization/generic/kubernetes-image-repository.md @@ -0,0 +1,30 @@ ++++ +title = "Kubernetes Image Repository" ++++ + +Override the container image repository used when pulling Kubernetes images. + +This customization will be available when the +[provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`. + +## Example + +To configure HTTP proxy values, specify the following configuration: + +```yaml +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: +spec: + topology: + variables: + - name: clusterConfig + value: + kubernetesImageRepository: "my-registry.io/my-org/my-repo" +``` + +Applying this configuration will result in the following value being set: + +- KubeadmControlPlaneTemplate: + - `/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/imageRepository: my-registry.io/my-org/my-repo` diff --git a/docs/content/etcd.md b/docs/content/etcd.md deleted file mode 100644 index a3a607030..000000000 --- a/docs/content/etcd.md +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: "etcd" ---- - -Override the container image repository and tag for [etcd](https://github.com/etcd-io/etcd). - -To enable this handler set the `etcdpatch` and `etcdvars` external patches on `ClusterClass`. - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: -spec: - patches: - - name: image-registry - external: - generateExtension: "etcdpatch.capi-runtime-extensions" - discoverVariablesExtension: "etcdvars.capi-runtime-extensions" -``` - -On the cluster resource then specify desired etcd image repository and/or image tag values: - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: -spec: - topology: - variables: - - name: etcd - values: - image: - repository: my-registry.io/my-org/my-repo - tag: "v3.5.99_custom.0" -``` - -Applying this configuration will result in the following value being set: - -- KubeadmControlPlaneTemplate: - - - ```yaml - spec: - kubeadmConfigSpec: - clusterConfiguration: - etcd: - local: - imageRepository: "my-registry.io/my-org/my-repo" - imageTag: "v3.5.99_custom.0" - ``` diff --git a/docs/content/extra-apiserver-cert-sans.md b/docs/content/extra-apiserver-cert-sans.md deleted file mode 100644 index 832da364a..000000000 --- a/docs/content/extra-apiserver-cert-sans.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "Extra API Server Certificate SANs" ---- - -If the API server can be accessed by alternative DNS addresses then setting additional SANs on the API server -certificate is necessary in order for clients to successfully validate the API server certificate. - -To enable the API server certificate SANs enable the `extraapiservercertsansvars` and `extraapiservercertsanspatch` -external patches on `ClusterClass`. - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: -spec: - patches: - - name: apiserver-cert-sans - external: - generateExtension: "extraapiservercertsanspatch.capi-runtime-extensions" - discoverVariablesExtension: "extraapiservercertsansvars.capi-runtime-extensions" -``` - -On the cluster resource then specify desired certificate SANs values: - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: -spec: - topology: - variables: - - name: extraAPIServerCertSANs - value: - - a.b.c.example.com - - d.e.f.example.com -``` - -Applying this configuration will result in the certificate SANs being correctly set in the -`KubeadmControlPlaneTemplate`. diff --git a/docs/content/http-proxy.md b/docs/content/http-proxy.md deleted file mode 100644 index c12481cbe..000000000 --- a/docs/content/http-proxy.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "HTTP proxy" ---- - -In some network environments it is necessary to use HTTP proxy to successfuly execute HTTP requests. -To configure Kubernetes components (`containerd`, `kubelet`) to use HTTP proxy use the `httpproxypatch` -external patch that will generate appropriate configuration for control plane and worker nodes. - -To enable the http proxy enable the `httpproxypatch` external patch on `ClusterClass`. - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: -spec: - patches: - - name: http-proxy - external: - generateExtension: "httpproxypatch.capi-runtime-extensions" - discoverVariablesExtension: "httpproxyvars.capi-runtime-extensions" -``` - -On the cluster resource then specify desired HTTP proxy values: - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: -spec: - topology: - variables: - - name: proxy - value: - http: http://example.com - https: http://example.com - additionalNo: - - no-proxy-1.example.com - - no-proxy-2.example.com -``` - -The `additionalNo` list will be added to default pre-calculated values that apply on k8s networking -`localhost,127.0.0.1,,,kubernetes,kubernetes.default,.svc,.svc.cluster.local`. - -Applying this configuration will result in new bootstrap files on the `KubeadmControlPlaneTemplate` -and `KubeadmConfigTemplate`. diff --git a/docs/content/kubernetes-image-repository.md b/docs/content/kubernetes-image-repository.md deleted file mode 100644 index 8be8b8dd2..000000000 --- a/docs/content/kubernetes-image-repository.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: "Kubernete Image Repository" ---- - -Override the container image repository used when pulling Kubernetes images. - -To enable this handler set the `imagerepositorypatch` and `imagerepositoryvars` external patches on `ClusterClass`. - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: -spec: - patches: - - name: image-repository - external: - generateExtension: "imagerepositorypatch.capi-runtime-extensions" - discoverVariablesExtension: "imagerepositoryvars.capi-runtime-extensions" -``` - -On the cluster resource then specify desired Kubernetes image repository value: - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: -spec: - topology: - variables: - - name: kubernetesImageRepository - value: "my-registry.io/my-org/my-repo" -``` - -Applying this configuration will result in the following value being set: - -- KubeadmControlPlaneTemplate: - - `/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/imageRepository: my-registry.io/my-org/my-repo` diff --git a/docs/content/lifecycle/_index.md b/docs/content/lifecycle/_index.md new file mode 100644 index 000000000..6db252951 --- /dev/null +++ b/docs/content/lifecycle/_index.md @@ -0,0 +1,3 @@ ++++ +title = "Lifecycle handlers" ++++ diff --git a/docs/content/service-loadbalancer-gc.md b/docs/content/lifecycle/service-loadbalancer-gc.md similarity index 93% rename from docs/content/service-loadbalancer-gc.md rename to docs/content/lifecycle/service-loadbalancer-gc.md index 019ad97dd..8c2dc2cda 100644 --- a/docs/content/service-loadbalancer-gc.md +++ b/docs/content/lifecycle/service-loadbalancer-gc.md @@ -1,6 +1,6 @@ ---- -title: "LoadBalancer Services Garbage Collection" ---- ++++ +title = "LoadBalancer Services Garbage Collection" ++++ When using Kubernetes `LoadBalancer` services, the relevant cloud provider interface creates and configures external resources. If the `LoadBalancer` services are not deleted prior to deleting the Kubernetes cluster, then these external diff --git a/docs/content/nfd.md b/docs/content/nfd.md deleted file mode 100644 index 0184dae5d..000000000 --- a/docs/content/nfd.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "Node Feature Discovery" ---- - -By leveraging CAPI cluster lifecycle hooks, this handler deploys [Node Feature -Discovery](https://github.com/kubernetes-sigs/node-feature-discovery) (NFD) on the new cluster via -`ClusterResourceSets` at the `AfterControlPlaneInitialized` phase. - -Deployment of NFD is opt-in using the following configuration for the lifecycle hook to perform any actions. The hook -creates a `ClusterResourceSet` to deploy the NFD resources. - -To enable the meta handler enable the `clusterconfigvars` and `clusterconfigpatch` external patches on `ClusterClass`. - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: ClusterClass -metadata: - name: -spec: - patches: - - name: cluster-config - external: - generateExtension: "clusterconfigpatch.capi-runtime-extensions" - discoverVariablesExtension: "clusterconfigvars.capi-runtime-extensions" -``` - -On the cluster resource then specify this `nfd` value: - -```yaml -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: -spec: - topology: - variables: - - name: clusterConfig - value: - addons: - nfd: {} -``` diff --git a/docs/go.mod b/docs/go.mod index e19146132..76e2d7376 100644 --- a/docs/go.mod +++ b/docs/go.mod @@ -5,4 +5,7 @@ module github.com/d2iq-labs/capi-runtime-extensions/docs go 1.20 -require github.com/google/docsy v0.7.1 // indirect +require ( + github.com/google/docsy v0.7.1 // indirect + github.com/google/docsy/dependencies v0.7.1 // indirect +) diff --git a/docs/go.sum b/docs/go.sum index d9ed4c51e..41de8b115 100644 --- a/docs/go.sum +++ b/docs/go.sum @@ -1,5 +1,6 @@ github.com/FortAwesome/Font-Awesome v0.0.0-20230327165841-0698449d50f2/go.mod h1:IUgezN/MFpCDIlFezw3L8j83oeiIuYoj28Miwr/KUYo= github.com/google/docsy v0.7.1 h1:DUriA7Nr3lJjNi9Ulev1SfiG1sUYmvyDeU4nTp7uDxY= github.com/google/docsy v0.7.1/go.mod h1:JCmE+c+izhE0Rvzv3y+AzHhz1KdwlA9Oj5YBMklJcfc= +github.com/google/docsy/dependencies v0.7.1 h1:NbzYKJYMin2q50xdWSUzR2c9gCp7zR/XHDBcxklEcTQ= github.com/google/docsy/dependencies v0.7.1/go.mod h1:gihhs5gmgeO+wuoay4FwOzob+jYJVyQbNaQOh788lD4= github.com/twbs/bootstrap v5.2.3+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0= diff --git a/docs/hugo.toml b/docs/hugo.toml index 5d7cb77d0..e2fc4a230 100644 --- a/docs/hugo.toml +++ b/docs/hugo.toml @@ -1,4 +1,3 @@ - baseURL = "https://d2iq-labs.github.io/capi-runtime-extensions" title = "CAPI Runtime Extensions | D2iQ Labs" @@ -105,24 +104,24 @@ prism_syntax_highlighting = true # User interface configuration [params.ui] -# Enable to show the side bar menu in its compact state. -sidebar_menu_compact = true # Set to true to disable breadcrumb navigation. breadcrumb_disable = false -# Set to true to hide the sidebar search box (the top nav search box will still be displayed if search is enabled) -sidebar_search_disable = false -# Set to false if you don't want to display a logo (/assets/icons/logo.svg) in the top nav bar -navbar_logo = false # Set to true to disable the About link in the site footer footer_about_disable = false +# Set to false if you don't want to display a logo (/assets/icons/logo.svg) in the top navbar +navbar_logo = true +# Set to true if you don't want the top navbar to be translucent when over a `block/cover`, like on the homepage. +navbar_translucent_over_cover_disable = false +# Enable to show the side bar menu in its compact state. +sidebar_menu_compact = true +# Set to true to hide the sidebar search box (the top nav search box will still be displayed if search is enabled) +sidebar_search_disable = false -# We have almost 200 attributes; don't truncate the sidebar to max 50 contents. -sidebar_menu_truncate = 1000 +ul_show = 2 -# Sidebar generation is slow otherwise -sidebar_cache_limit = 100 +sidebar_menu_foldable = true -ul_show = 2 +sidebar_cache_limit = 1000 # Adds a H2 section titled "Feedback" to the bottom of each doc. The responses are sent to Google Analytics as events. # This feature depends on [services.googleAnalytics] and will be disabled if "services.googleAnalytics.id" is not set. @@ -162,7 +161,9 @@ url = "https://github.com/d2iq-labs/capi-runtime-extensions" [params.taxonomy] [module] - proxy = "direct" + [module.hugoVersion] + extended = true + min = "0.11.0" [[module.imports]] path = "github.com/google/docsy" [[module.imports]] diff --git a/examples/capi-quick-start/aws-cluster-class.yaml b/examples/capi-quick-start/aws-cluster-class.yaml index c87b30e4d..8be958785 100644 --- a/examples/capi-quick-start/aws-cluster-class.yaml +++ b/examples/capi-quick-start/aws-cluster-class.yaml @@ -21,14 +21,10 @@ spec: kind: AWSClusterTemplate name: aws-quick-start patches: - - external: - discoverVariablesExtension: clusterconfigvars.capi-runtime-extensions - generateExtension: clusterconfigpatch.capi-runtime-extensions - name: cluster-config - external: discoverVariablesExtension: awsclusterconfigvars.capi-runtime-extensions generateExtension: awsclusterconfigpatch.capi-runtime-extensions - name: aws-cluster-config + name: cluster-config - definitions: - jsonPatches: - op: add diff --git a/examples/capi-quick-start/aws-cluster.yaml b/examples/capi-quick-start/aws-cluster.yaml index bcef17ee1..1271090ed 100644 --- a/examples/capi-quick-start/aws-cluster.yaml +++ b/examples/capi-quick-start/aws-cluster.yaml @@ -24,8 +24,6 @@ spec: cni: provider: calico nfd: {} - - name: awsClusterConfig - value: {} version: v1.27.5 workers: machineDeployments: diff --git a/examples/capi-quick-start/docker-cluster-class.yaml b/examples/capi-quick-start/docker-cluster-class.yaml index 4cec328b6..56e67bdea 100644 --- a/examples/capi-quick-start/docker-cluster-class.yaml +++ b/examples/capi-quick-start/docker-cluster-class.yaml @@ -22,8 +22,8 @@ spec: name: docker-quick-start-cluster patches: - external: - discoverVariablesExtension: clusterconfigvars.capi-runtime-extensions - generateExtension: clusterconfigpatch.capi-runtime-extensions + discoverVariablesExtension: dockerclusterconfigvars.capi-runtime-extensions + generateExtension: dockerclusterconfigpatch.capi-runtime-extensions name: cluster-config - definitions: - jsonPatches: diff --git a/hack/examples/bases/aws/kustomization.yaml.tmpl b/hack/examples/bases/aws/kustomization.yaml.tmpl index 5aaac995d..124802eb9 100644 --- a/hack/examples/bases/aws/kustomization.yaml.tmpl +++ b/hack/examples/bases/aws/kustomization.yaml.tmpl @@ -29,7 +29,7 @@ patches: - op: "add" path: "/spec/topology/variables" value: - - name: "awsClusterConfig" + - name: "clusterConfig" value: {} - target: group: cluster.x-k8s.io @@ -71,7 +71,7 @@ patches: - op: "add" path: "/spec/patches/0" value: - name: "aws-cluster-config" + name: "cluster-config" external: generateExtension: "awsclusterconfigpatch.capi-runtime-extensions" discoverVariablesExtension: "awsclusterconfigvars.capi-runtime-extensions" diff --git a/hack/examples/bases/docker/kustomization.yaml.tmpl b/hack/examples/bases/docker/kustomization.yaml.tmpl index f13a35748..9b29a5db6 100644 --- a/hack/examples/bases/docker/kustomization.yaml.tmpl +++ b/hack/examples/bases/docker/kustomization.yaml.tmpl @@ -28,7 +28,9 @@ patches: value: "docker-quick-start" - op: "add" path: "/spec/topology/variables" - value: [] + value: + - name: "clusterConfig" + value: {} - target: group: cluster.x-k8s.io kind: ClusterClass @@ -75,5 +77,12 @@ patches: path: /spec/template/spec/customImage valueFrom: template: ghcr.io/mesosphere/kind-node:{{ .builtin.controlPlane.version }} + - op: "add" + path: "/spec/patches/0" + value: + name: "cluster-config" + external: + generateExtension: "dockerclusterconfigpatch.capi-runtime-extensions" + discoverVariablesExtension: "dockerclusterconfigvars.capi-runtime-extensions" - op: "remove" path: "/spec/variables" diff --git a/hack/examples/kustomization.yaml.tmpl b/hack/examples/kustomization.yaml.tmpl index c9753eca1..3625c603f 100644 --- a/hack/examples/kustomization.yaml.tmpl +++ b/hack/examples/kustomization.yaml.tmpl @@ -12,17 +12,6 @@ resources: - ./bases/aws patches: -- target: - group: cluster.x-k8s.io - kind: ClusterClass - patch: |- - - op: "add" - path: "/spec/patches/0" - value: - name: "cluster-config" - external: - generateExtension: "clusterconfigpatch.capi-runtime-extensions" - discoverVariablesExtension: "clusterconfigvars.capi-runtime-extensions" - target: group: cluster.x-k8s.io kind: Cluster @@ -50,11 +39,8 @@ patches: path: "/spec/topology/workers/machineDeployments/0/replicas" value: 1 - op: "add" - path: "/spec/topology/variables/0" + path: "/spec/topology/variables/0/value/addons" value: - name: "clusterConfig" - value: - addons: - cni: - provider: calico - nfd: {} + cni: + provider: calico + nfd: {} diff --git a/pkg/handlers/aws/clusterconfig/variables.go b/pkg/handlers/aws/clusterconfig/variables.go index 6cedab3e0..4cc5d005f 100644 --- a/pkg/handlers/aws/clusterconfig/variables.go +++ b/pkg/handlers/aws/clusterconfig/variables.go @@ -12,6 +12,7 @@ import ( "github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1" commonhandlers "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/handlers" "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/handlers/mutation" + "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig" ) var ( @@ -20,9 +21,6 @@ var ( ) const ( - // MetaVariableName is the meta cluster config patch variable name. - MetaVariableName = "awsClusterConfig" - // HandlerNameVariable is the name of the variable handler. HandlerNameVariable = "AWSClusterConfigVars" ) @@ -43,7 +41,7 @@ func (h *awsClusterConfigVariableHandler) DiscoverVariables( resp *runtimehooksv1.DiscoverVariablesResponse, ) { resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ - Name: MetaVariableName, + Name: clusterconfig.MetaVariableName, Required: true, Schema: v1alpha1.AWSClusterConfigSpec{}.VariableSchema(), }) diff --git a/pkg/handlers/aws/clusterconfig/variables_test.go b/pkg/handlers/aws/clusterconfig/variables_test.go index a15c5154e..6aa8bce29 100644 --- a/pkg/handlers/aws/clusterconfig/variables_test.go +++ b/pkg/handlers/aws/clusterconfig/variables_test.go @@ -10,12 +10,13 @@ import ( "github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1" "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/testutils/capitest" + "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig" ) func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, - MetaVariableName, + clusterconfig.MetaVariableName, ptr.To(v1alpha1.AWSClusterConfigSpec{}.VariableSchema()), true, NewVariable, diff --git a/pkg/handlers/aws/mutation/region/inject.go b/pkg/handlers/aws/mutation/region/inject.go index 3fd9c163c..81d645a85 100644 --- a/pkg/handlers/aws/mutation/region/inject.go +++ b/pkg/handlers/aws/mutation/region/inject.go @@ -22,7 +22,7 @@ import ( "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/patches" "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/patches/selectors" "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/variables" - "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/aws/clusterconfig" + "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig" ) const ( diff --git a/pkg/handlers/docker/clusterconfig/variables.go b/pkg/handlers/docker/clusterconfig/variables.go new file mode 100644 index 000000000..1c1161977 --- /dev/null +++ b/pkg/handlers/docker/clusterconfig/variables.go @@ -0,0 +1,49 @@ +// Copyright 2023 D2iQ, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package clusterconfig + +import ( + "context" + + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" + + "github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1" + commonhandlers "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/handlers" + "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/handlers/mutation" + "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig" +) + +var ( + _ commonhandlers.Named = &dockerClusterConfigVariableHandler{} + _ mutation.DiscoverVariables = &dockerClusterConfigVariableHandler{} +) + +const ( + // HandlerNameVariable is the name of the variable handler. + HandlerNameVariable = "DockerClusterConfigVars" +) + +func NewVariable() *dockerClusterConfigVariableHandler { + return &dockerClusterConfigVariableHandler{} +} + +type dockerClusterConfigVariableHandler struct{} + +func (h *dockerClusterConfigVariableHandler) Name() string { + return HandlerNameVariable +} + +func (h *dockerClusterConfigVariableHandler) DiscoverVariables( + ctx context.Context, + _ *runtimehooksv1.DiscoverVariablesRequest, + resp *runtimehooksv1.DiscoverVariablesResponse, +) { + resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ + Name: clusterconfig.MetaVariableName, + Required: true, + Schema: v1alpha1.DockerClusterConfigSpec{}.VariableSchema(), + }) + resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) +} diff --git a/pkg/handlers/docker/clusterconfig/variables_test.go b/pkg/handlers/docker/clusterconfig/variables_test.go new file mode 100644 index 000000000..63eaa2fef --- /dev/null +++ b/pkg/handlers/docker/clusterconfig/variables_test.go @@ -0,0 +1,24 @@ +// Copyright 2023 D2iQ, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package clusterconfig + +import ( + "testing" + + "k8s.io/utils/ptr" + + "github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1" + "github.com/d2iq-labs/capi-runtime-extensions/common/pkg/testutils/capitest" + "github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/generic/clusterconfig" +) + +func TestVariableValidation(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfigSpec{}.VariableSchema()), + true, + NewVariable, + ) +} diff --git a/pkg/handlers/generic/clusterconfig/variables.go b/pkg/handlers/generic/clusterconfig/variables.go index 0ad82bd48..c82fcb274 100644 --- a/pkg/handlers/generic/clusterconfig/variables.go +++ b/pkg/handlers/generic/clusterconfig/variables.go @@ -45,7 +45,7 @@ func (h *clusterConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: MetaVariableName, Required: false, - Schema: v1alpha1.ClusterConfigSpec{}.VariableSchema(), + Schema: v1alpha1.GenericClusterConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/generic/clusterconfig/variables_test.go b/pkg/handlers/generic/clusterconfig/variables_test.go index d40b06418..3142120be 100644 --- a/pkg/handlers/generic/clusterconfig/variables_test.go +++ b/pkg/handlers/generic/clusterconfig/variables_test.go @@ -16,12 +16,12 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, MetaVariableName, - ptr.To(v1alpha1.ClusterConfigSpec{}.VariableSchema()), + ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), false, NewVariable, capitest.VariableTestDef{ Name: "valid proxy config only", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.GenericClusterConfig{ Proxy: &v1alpha1.HTTPProxy{ HTTP: "http://a.b.c.example.com", HTTPS: "https://a.b.c.example.com", @@ -31,20 +31,20 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "single valid SAN", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.GenericClusterConfig{ ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{"a.b.c.example.com"}, }, }, capitest.VariableTestDef{ Name: "single invalid SAN", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.GenericClusterConfig{ ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{"invalid:san"}, }, ExpectError: true, }, capitest.VariableTestDef{ Name: "duplicate valid SANs", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.GenericClusterConfig{ ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ "a.b.c.example.com", "a.b.c.example.com", @@ -53,7 +53,7 @@ func TestVariableValidation(t *testing.T) { ExpectError: true, }, capitest.VariableTestDef{ Name: "valid config", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.GenericClusterConfig{ Proxy: &v1alpha1.HTTPProxy{ HTTP: "http://a.b.c.example.com", HTTPS: "https://a.b.c.example.com", diff --git a/pkg/handlers/generic/lifecycle/cni/calico/handler.go b/pkg/handlers/generic/lifecycle/cni/calico/handler.go index cd48ae7ad..7aa723da2 100644 --- a/pkg/handlers/generic/lifecycle/cni/calico/handler.go +++ b/pkg/handlers/generic/lifecycle/cni/calico/handler.go @@ -83,7 +83,7 @@ var ( calicoInstallationGK = schema.GroupKind{Group: "operator.tigera.io", Kind: "Installation"} ) -func NewMetaHandler( +func New( c ctrlclient.Client, cfg *CalicoCNIConfig, ) *CalicoCNI { diff --git a/pkg/handlers/generic/lifecycle/nfd/handler.go b/pkg/handlers/generic/lifecycle/nfd/handler.go index a8498eb54..b830dcc3b 100644 --- a/pkg/handlers/generic/lifecycle/nfd/handler.go +++ b/pkg/handlers/generic/lifecycle/nfd/handler.go @@ -55,7 +55,7 @@ const ( variableName = "nfd" ) -func NewMetaHandler( +func New( c ctrlclient.Client, cfg *NFDConfig, ) *DefaultNFD {