From 4ea2196ec8c888ca27ffe23b66626fc89bed0998 Mon Sep 17 00:00:00 2001 From: Oprin Marius Date: Sat, 2 Mar 2024 13:25:23 +0200 Subject: [PATCH 1/4] Add support for provider specific featureGates --- hack/charts/cluster-api-operator/templates/infra.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hack/charts/cluster-api-operator/templates/infra.yaml b/hack/charts/cluster-api-operator/templates/infra.yaml index d7b46e71..5f813a22 100644 --- a/hack/charts/cluster-api-operator/templates/infra.yaml +++ b/hack/charts/cluster-api-operator/templates/infra.yaml @@ -46,10 +46,14 @@ spec: {{- end }} {{- if $.Values.manager }} manager: -{{- if $.Values.manager.featureGates }} - featureGates: +{{- if hasKey $.Values.manager.featureGates $infrastructureName }} {{- range $key, $value := $.Values.manager.featureGates }} - {{ $key }}: {{ $value }} + {{- if eq $key $infrastructureName }} + featureGates: + {{- range $k, $v := $value }} + {{ $k }}: {{ $v }} + {{- end }} + {{- end }} {{- end }} {{- end }} {{- end }} From 32b1b3a8633c7fc40578c39c1b20cac94135e55c Mon Sep 17 00:00:00 2001 From: Oprin Marius Date: Sat, 2 Mar 2024 13:25:45 +0200 Subject: [PATCH 2/4] Add featureGates to CoreProvider --- hack/charts/cluster-api-operator/templates/core.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hack/charts/cluster-api-operator/templates/core.yaml b/hack/charts/cluster-api-operator/templates/core.yaml index 260efb59..4235cd71 100644 --- a/hack/charts/cluster-api-operator/templates/core.yaml +++ b/hack/charts/cluster-api-operator/templates/core.yaml @@ -43,6 +43,15 @@ spec: {{- if $coreVersion }} version: {{ $coreVersion }} {{- end }} +{{- if $.Values.manager }} + manager: +{{- if $.Values.manager.featureGates.core }} + featureGates: + {{- range $key, $value := $.Values.manager.featureGates.core }} + {{ $key }}: {{ $value }} + {{- end }} +{{- end }} +{{- end }} {{- if $.Values.configSecret.name }} configSecret: name: {{ $.Values.configSecret.name }} From a0b1e3e5bbff6acb0f24b9bf4eadfb5973096b4f Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Wed, 27 Mar 2024 21:06:49 +0100 Subject: [PATCH 3/4] Added test --- test/e2e/helm_test.go | 23 +++ test/e2e/resources/feature-gates.yaml | 230 ++++++++++++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 test/e2e/resources/feature-gates.yaml diff --git a/test/e2e/helm_test.go b/test/e2e/helm_test.go index 066ca938..9f109ab8 100644 --- a/test/e2e/helm_test.go +++ b/test/e2e/helm_test.go @@ -206,4 +206,27 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func Expect(err).ToNot(HaveOccurred()) Expect(manifests).To(Equal(string(expectedManifests))) }) + It("should deploy core and infra with feature gates enabled", func() { + manifests, err := helmChart.Run(map[string]string{ + "configSecret.name": "aws-variables", + "configSecret.namespace": "default", + "infrastructure": "aws:v2.4.0", + "addon": "helm:", + "image.manager.tag": "v0.9.1", + "cert-manager.enabled": "false", + "cert-manager.installCRDs": "false", + "core": "cluster-api:v1.6.2", + "manager.featureGates.core.ClusterTopology": "true", + "manager.featureGates.core.MachinePool": "true", + "manager.featureGates.aws.ClusterTopology": "true", + "manager.featureGates.aws.MachinePool": "true", + "manager.featureGates.aws.EKSEnableIAM": "true", + "manager.featureGates.aws.EKSAllowAddRoles": "true", + }) + Expect(err).ToNot(HaveOccurred()) + Expect(manifests).ToNot(BeEmpty()) + expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "feature-gates.yaml")) + Expect(err).ToNot(HaveOccurred()) + Expect(manifests).To(Equal(string(expectedManifests))) + }) }) diff --git a/test/e2e/resources/feature-gates.yaml b/test/e2e/resources/feature-gates.yaml new file mode 100644 index 00000000..60970fd8 --- /dev/null +++ b/test/e2e/resources/feature-gates.yaml @@ -0,0 +1,230 @@ +--- +# Source: cluster-api-operator/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: capi-cluster-api-operator + namespace: 'default' + labels: + app: cluster-api-operator + app.kubernetes.io/name: cluster-api-operator + app.kubernetes.io/instance: capi + app.kubernetes.io/component: "controller" + control-plane: controller-manager + clusterctl.cluster.x-k8s.io/core: capi-operator +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: cluster-api-operator + app.kubernetes.io/instance: capi + app.kubernetes.io/component: "controller" + control-plane: controller-manager + clusterctl.cluster.x-k8s.io/core: capi-operator + template: + metadata: + labels: + app: cluster-api-operator + app.kubernetes.io/name: cluster-api-operator + app.kubernetes.io/instance: capi + app.kubernetes.io/component: "controller" + control-plane: controller-manager + clusterctl.cluster.x-k8s.io/core: capi-operator + spec: + containers: + - args: + - --v=2 + - --health-addr=:8081 + - --metrics-bind-addr=127.0.0.1:8080 + - --diagnostics-address=8443 + - --leader-elect=true + command: + - /manager + image: "gcr.io/k8s-staging-capi-operator/cluster-api-operator:v0.9.1" + imagePullPolicy: IfNotPresent + name: manager + ports: + - containerPort: 9443 + name: webhook-server + protocol: TCP + resources: + limits: + cpu: 100m + memory: 150Mi + requests: + cpu: 100m + memory: 100Mi + volumeMounts: + - mountPath: /tmp/k8s-webhook-server/serving-certs + name: cert + readOnly: true + terminationGracePeriodSeconds: 10 + volumes: + - name: cert + secret: + defaultMode: 420 + secretName: capi-operator-webhook-service-cert + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/arch + operator: In + values: + - amd64 + - arm64 + - ppc64le + - key: kubernetes.io/os + operator: In + values: + - linux + tolerations: + - effect: NoSchedule + key: node-role.kubernetes.io/master + - effect: NoSchedule + key: node-role.kubernetes.io/control-plane +--- +# Source: cluster-api-operator/templates/addon.yaml +# Addon provider +--- +# Source: cluster-api-operator/templates/bootstrap.yaml +# Bootstrap provider +--- +# Source: cluster-api-operator/templates/control-plane.yaml +# Control plane provider +--- +# Source: cluster-api-operator/templates/core-conditions.yaml +# Deploy core components if not specified +--- +# Source: cluster-api-operator/templates/core.yaml +# Core provider +--- +# Source: cluster-api-operator/templates/infra-conditions.yaml +# Deploy bootstrap, and infrastructure components if not specified +--- +# Source: cluster-api-operator/templates/infra.yaml +# Infrastructure providers +--- +# Source: cluster-api-operator/templates/addon.yaml +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "1" + name: helm-addon-system +--- +# Source: cluster-api-operator/templates/core.yaml +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "1" + name: capi-system +--- +# Source: cluster-api-operator/templates/infra-conditions.yaml +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "1" + name: capi-kubeadm-bootstrap-system +--- +# Source: cluster-api-operator/templates/infra-conditions.yaml +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "1" + name: capi-kubeadm-control-plane-system +--- +# Source: cluster-api-operator/templates/infra.yaml +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "1" + name: aws-infrastructure-system +--- +# Source: cluster-api-operator/templates/addon.yaml +apiVersion: operator.cluster.x-k8s.io/v1alpha2 +kind: AddonProvider +metadata: + name: helm + namespace: helm-addon-system + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "2" +--- +# Source: cluster-api-operator/templates/infra-conditions.yaml +apiVersion: operator.cluster.x-k8s.io/v1alpha2 +kind: BootstrapProvider +metadata: + name: kubeadm + namespace: capi-kubeadm-bootstrap-system + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "2" +spec: + configSecret: + name: aws-variables + namespace: default +--- +# Source: cluster-api-operator/templates/infra-conditions.yaml +apiVersion: operator.cluster.x-k8s.io/v1alpha2 +kind: ControlPlaneProvider +metadata: + name: kubeadm + namespace: capi-kubeadm-control-plane-system + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "2" +spec: + configSecret: + name: aws-variables + namespace: default +--- +# Source: cluster-api-operator/templates/core.yaml +apiVersion: operator.cluster.x-k8s.io/v1alpha2 +kind: CoreProvider +metadata: + name: cluster-api + namespace: capi-system + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "2" +spec: + version: v1.6.2 + manager: + featureGates: + ClusterTopology: true + MachinePool: true + configSecret: + name: aws-variables + namespace: default +--- +# Source: cluster-api-operator/templates/infra.yaml +apiVersion: operator.cluster.x-k8s.io/v1alpha2 +kind: InfrastructureProvider +metadata: + name: aws + namespace: aws-infrastructure-system + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "2" +spec: + version: v2.4.0 + manager: + featureGates: + ClusterTopology: true + EKSAllowAddRoles: true + EKSEnableIAM: true + MachinePool: true + configSecret: + name: aws-variables + namespace: default From f7f569d7d1566904149514c5057bc479d01b5f12 Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Fri, 5 Apr 2024 12:52:55 +0200 Subject: [PATCH 4/4] Remove capi-cluster-api-operator deployment from expected yaml test file --- test/e2e/resources/feature-gates.yaml | 109 +------------------------- 1 file changed, 1 insertion(+), 108 deletions(-) diff --git a/test/e2e/resources/feature-gates.yaml b/test/e2e/resources/feature-gates.yaml index 60970fd8..2bc1baa8 100644 --- a/test/e2e/resources/feature-gates.yaml +++ b/test/e2e/resources/feature-gates.yaml @@ -1,111 +1,4 @@ --- -# Source: cluster-api-operator/templates/deployment.yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: capi-cluster-api-operator - namespace: 'default' - labels: - app: cluster-api-operator - app.kubernetes.io/name: cluster-api-operator - app.kubernetes.io/instance: capi - app.kubernetes.io/component: "controller" - control-plane: controller-manager - clusterctl.cluster.x-k8s.io/core: capi-operator -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/name: cluster-api-operator - app.kubernetes.io/instance: capi - app.kubernetes.io/component: "controller" - control-plane: controller-manager - clusterctl.cluster.x-k8s.io/core: capi-operator - template: - metadata: - labels: - app: cluster-api-operator - app.kubernetes.io/name: cluster-api-operator - app.kubernetes.io/instance: capi - app.kubernetes.io/component: "controller" - control-plane: controller-manager - clusterctl.cluster.x-k8s.io/core: capi-operator - spec: - containers: - - args: - - --v=2 - - --health-addr=:8081 - - --metrics-bind-addr=127.0.0.1:8080 - - --diagnostics-address=8443 - - --leader-elect=true - command: - - /manager - image: "gcr.io/k8s-staging-capi-operator/cluster-api-operator:v0.9.1" - imagePullPolicy: IfNotPresent - name: manager - ports: - - containerPort: 9443 - name: webhook-server - protocol: TCP - resources: - limits: - cpu: 100m - memory: 150Mi - requests: - cpu: 100m - memory: 100Mi - volumeMounts: - - mountPath: /tmp/k8s-webhook-server/serving-certs - name: cert - readOnly: true - terminationGracePeriodSeconds: 10 - volumes: - - name: cert - secret: - defaultMode: 420 - secretName: capi-operator-webhook-service-cert - affinity: - nodeAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - - matchExpressions: - - key: kubernetes.io/arch - operator: In - values: - - amd64 - - arm64 - - ppc64le - - key: kubernetes.io/os - operator: In - values: - - linux - tolerations: - - effect: NoSchedule - key: node-role.kubernetes.io/master - - effect: NoSchedule - key: node-role.kubernetes.io/control-plane ---- -# Source: cluster-api-operator/templates/addon.yaml -# Addon provider ---- -# Source: cluster-api-operator/templates/bootstrap.yaml -# Bootstrap provider ---- -# Source: cluster-api-operator/templates/control-plane.yaml -# Control plane provider ---- -# Source: cluster-api-operator/templates/core-conditions.yaml -# Deploy core components if not specified ---- -# Source: cluster-api-operator/templates/core.yaml -# Core provider ---- -# Source: cluster-api-operator/templates/infra-conditions.yaml -# Deploy bootstrap, and infrastructure components if not specified ---- -# Source: cluster-api-operator/templates/infra.yaml -# Infrastructure providers ---- # Source: cluster-api-operator/templates/addon.yaml apiVersion: v1 kind: Namespace @@ -227,4 +120,4 @@ spec: MachinePool: true configSecret: name: aws-variables - namespace: default + namespace: default \ No newline at end of file