diff --git a/hack/charts/cluster-api-operator/templates/addon.yaml b/hack/charts/cluster-api-operator/templates/addon.yaml index c571b60aa..4d8b96f46 100644 --- a/hack/charts/cluster-api-operator/templates/addon.yaml +++ b/hack/charts/cluster-api-operator/templates/addon.yaml @@ -53,4 +53,7 @@ spec: secretNamespace: {{ $.Values.secretNamespace }} {{- end }} {{- end }} +{{- if hasKey (default (dict) $.Values.deploymentOverride) "addon" }} + {{ .Values.deploymentOverride.addon | toYaml | nindent 2 }} +{{- end }} {{- end }} diff --git a/hack/charts/cluster-api-operator/templates/bootstrap.yaml b/hack/charts/cluster-api-operator/templates/bootstrap.yaml index 69a930f2a..3ea81876f 100644 --- a/hack/charts/cluster-api-operator/templates/bootstrap.yaml +++ b/hack/charts/cluster-api-operator/templates/bootstrap.yaml @@ -52,4 +52,7 @@ spec: {{- end }} {{- end }} {{- end }} +{{- if hasKey (default (dict) $.Values.deploymentOverride) "bootstrap" }} + {{ .Values.deploymentOverride.bootstrap | toYaml | nindent 2 }} {{- end }} +{{- end }} \ No newline at end of file diff --git a/hack/charts/cluster-api-operator/templates/control-plane.yaml b/hack/charts/cluster-api-operator/templates/control-plane.yaml index c8eaedc4d..1d39013bc 100644 --- a/hack/charts/cluster-api-operator/templates/control-plane.yaml +++ b/hack/charts/cluster-api-operator/templates/control-plane.yaml @@ -65,4 +65,8 @@ spec: {{- end }} {{- end }} {{- end }} +{{- if hasKey (default (dict) $.Values.deploymentOverride) "controlPlane" }} + {{ .Values.deploymentOverride.controlPlane | toYaml | nindent 2 }} {{- end }} +{{- end }} + diff --git a/hack/charts/cluster-api-operator/templates/core-conditions.yaml b/hack/charts/cluster-api-operator/templates/core-conditions.yaml index bb396a24b..8d5863db7 100644 --- a/hack/charts/cluster-api-operator/templates/core-conditions.yaml +++ b/hack/charts/cluster-api-operator/templates/core-conditions.yaml @@ -27,5 +27,7 @@ spec: {{- end }} {{- end }} {{- end }} +{{- if hasKey (default (dict) $.Values.deploymentOverride ) "coreCondition" }} + {{ .Values.deploymentOverride.coreCondition| toYaml | nindent 2 }} {{- end }} - +{{- end }} \ No newline at end of file diff --git a/hack/charts/cluster-api-operator/templates/core.yaml b/hack/charts/cluster-api-operator/templates/core.yaml index 2d0d8b76c..a1a367aaa 100644 --- a/hack/charts/cluster-api-operator/templates/core.yaml +++ b/hack/charts/cluster-api-operator/templates/core.yaml @@ -60,4 +60,7 @@ spec: namespace: {{ $.Values.configSecret.namespace }} {{- end }} {{- end }} +{{- if hasKey (default (dict) $.Values.deploymentOverride) "core" }} + {{ .Values.deploymentOverride.core | toYaml | nindent 2 }} +{{- end }} {{- end }} diff --git a/hack/charts/cluster-api-operator/templates/infra-conditions.yaml b/hack/charts/cluster-api-operator/templates/infra-conditions.yaml index a311684e6..628cc43e6 100644 --- a/hack/charts/cluster-api-operator/templates/infra-conditions.yaml +++ b/hack/charts/cluster-api-operator/templates/infra-conditions.yaml @@ -69,5 +69,8 @@ spec: {{- end }} {{- end }} {{- end }} - +{{- if hasKey (default (dict) $.Values.deploymentOverride ) "infraCondition" }} + {{ .Values.deploymentOverride.infraCondition | toYaml | nindent 2 }} +{{- end }} {{- end }} + diff --git a/hack/charts/cluster-api-operator/templates/infra.yaml b/hack/charts/cluster-api-operator/templates/infra.yaml index 269bffd13..1f6c002a5 100644 --- a/hack/charts/cluster-api-operator/templates/infra.yaml +++ b/hack/charts/cluster-api-operator/templates/infra.yaml @@ -70,4 +70,7 @@ spec: additionalDeployments: {{ toYaml $.Values.additionalDeployments | nindent 4 }} {{- end }} {{- end }} +{{- if hasKey (default (dict) $.Values.deploymentOverride ) "infrastructure" }} + {{ .Values.deploymentOverride.infrastructure | toYaml | nindent 2 }} +{{- end }} {{- end }} diff --git a/test/e2e/helm_test.go b/test/e2e/helm_test.go index d381be617..9e48d73ed 100644 --- a/test/e2e/helm_test.go +++ b/test/e2e/helm_test.go @@ -261,6 +261,40 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func Expect(err).ToNot(HaveOccurred()) Expect(manifests).To(MatchYAML(string(expectedManifests))) }) +It("should include deplpoymentoverrides when specified - infrastructure", func() { + manifests, err := helmChart.Run(map[string]string{ + "configSecret.name": "test-secret-name", + "configSecret.namespace": "test-secret-namespace", + "infrastructure": "docker", + "addon": "helm", + "deploymentOverride.infrastructure.deployment.containers[0].name": "manager", + "deploymentOverride.infrastructure.deployment.containers[0].imageUrl": "test.org/cluster-api-vsphere/cluster-api-vsphere-controller:v1.10.0", + }) + Expect(err).ToNot(HaveOccurred()) + Expect(manifests).ToNot(BeEmpty()) + expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "only-infra-and-addon-override.yaml")) + Expect(err).ToNot(HaveOccurred()) + Expect(manifests).To(MatchYAML(string(expectedManifests))) + }) + + It("should include deplpoymentoverrides when specified - addon and infra", func() { + manifests, err := helmChart.Run(map[string]string{ + "configSecret.name": "test-secret-name", + "configSecret.namespace": "test-secret-namespace", + "infrastructure": "docker", + "addon": "helm", + "deploymentOverride.addon.deployment.containers[0].name": "manager", + "deploymentOverride.addon.deployment.containers[0].imageUrl": "test.org/cluster-api-vsphere/cluster-api-vsphere-controller:v1.10.0", + "deploymentOverride.infrastructure.deployment.containers[0].name": "manager", + "deploymentOverride.infrastructure.deployment.containers[0].imageUrl": "test.org/cluster-api-vsphere/cluster-api-vsphere-controller:v1.10.0", + }) + Expect(err).ToNot(HaveOccurred()) + Expect(manifests).ToNot(BeEmpty()) + expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "addon-and-infra-override.yaml")) + Expect(err).ToNot(HaveOccurred()) + Expect(manifests).To(MatchYAML(string(expectedManifests))) + }) + It("should deploy kubeadm control plane with manager specified", func() { manifests, err := helmChart.Run(map[string]string{ "core": "cluster-api", @@ -276,5 +310,4 @@ var _ = Describe("Create a proper set of manifests when using helm charts", func expectedManifests, err := os.ReadFile(filepath.Join(customManifestsFolder, "kubeadm-manager-defined.yaml")) Expect(err).ToNot(HaveOccurred()) Expect(manifests).To(MatchYAML(string(expectedManifests))) - }) -}) + }) \ No newline at end of file diff --git a/test/e2e/resources/addon-and-infra-override.yaml b/test/e2e/resources/addon-and-infra-override.yaml new file mode 100644 index 000000000..bce930634 --- /dev/null +++ b/test/e2e/resources/addon-and-infra-override.yaml @@ -0,0 +1,128 @@ +--- +# Source: cluster-api-operator/templates/addon.yaml +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "1" + "argocd.argoproj.io/sync-wave": "1" + name: helm-addon-system +--- +# Source: cluster-api-operator/templates/core-conditions.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" + "argocd.argoproj.io/sync-wave": "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" + "argocd.argoproj.io/sync-wave": "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" + "argocd.argoproj.io/sync-wave": "1" + name: docker-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" + "argocd.argoproj.io/sync-wave": "2" +spec: + deployment: + containers: + - imageUrl: test.org/cluster-api-vsphere/cluster-api-vsphere-controller:v1.10.0 + name: manager +--- +# 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" + "argocd.argoproj.io/sync-wave": "2" +spec: + configSecret: + name: test-secret-name + namespace: test-secret-namespace +--- +# 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" + "argocd.argoproj.io/sync-wave": "2" +spec: + configSecret: + name: test-secret-name + namespace: test-secret-namespace +--- +# Source: cluster-api-operator/templates/core-conditions.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: + configSecret: + name: test-secret-name + namespace: test-secret-namespace +--- +# Source: cluster-api-operator/templates/infra.yaml +apiVersion: operator.cluster.x-k8s.io/v1alpha2 +kind: InfrastructureProvider +metadata: + name: docker + namespace: docker-infrastructure-system + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "2" + "argocd.argoproj.io/sync-wave": "2" +spec: + configSecret: + name: test-secret-name + namespace: test-secret-namespace + deployment: + containers: + - imageUrl: test.org/cluster-api-vsphere/cluster-api-vsphere-controller:v1.10.0 + name: manager \ No newline at end of file diff --git a/test/e2e/resources/only-infra-and-addon-override.yaml b/test/e2e/resources/only-infra-and-addon-override.yaml new file mode 100644 index 000000000..92b23fa65 --- /dev/null +++ b/test/e2e/resources/only-infra-and-addon-override.yaml @@ -0,0 +1,123 @@ +--- +# Source: cluster-api-operator/templates/addon.yaml +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "1" + "argocd.argoproj.io/sync-wave": "1" + name: helm-addon-system +--- +# Source: cluster-api-operator/templates/core-conditions.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" + "argocd.argoproj.io/sync-wave": "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" + "argocd.argoproj.io/sync-wave": "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" + "argocd.argoproj.io/sync-wave": "1" + name: docker-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" + "argocd.argoproj.io/sync-wave": "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" + "argocd.argoproj.io/sync-wave": "2" +spec: + configSecret: + name: test-secret-name + namespace: test-secret-namespace +--- +# 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" + "argocd.argoproj.io/sync-wave": "2" +spec: + configSecret: + name: test-secret-name + namespace: test-secret-namespace +--- +# Source: cluster-api-operator/templates/core-conditions.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: + configSecret: + name: test-secret-name + namespace: test-secret-namespace +--- +# Source: cluster-api-operator/templates/infra.yaml +apiVersion: operator.cluster.x-k8s.io/v1alpha2 +kind: InfrastructureProvider +metadata: + name: docker + namespace: docker-infrastructure-system + annotations: + "helm.sh/hook": "post-install" + "helm.sh/hook-weight": "2" + "argocd.argoproj.io/sync-wave": "2" +spec: + configSecret: + name: test-secret-name + namespace: test-secret-namespace + deployment: + containers: + - imageUrl: test.org/cluster-api-vsphere/cluster-api-vsphere-controller:v1.10.0 + name: manager \ No newline at end of file