Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add deployment overrides to templates #525

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hack/charts/cluster-api-operator/templates/addon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
3 changes: 3 additions & 0 deletions hack/charts/cluster-api-operator/templates/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if hasKey (default (dict) $.Values.deploymentOverride) "bootstrap" }}
{{ .Values.deploymentOverride.bootstrap | toYaml | nindent 2 }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessarily a deployment override, or? It allows to add custom stuff to the provider CR, which could be anything? Maybe the word 'deployment' is confusing here.
(I came here when looking for a way to add a manifestPatches key to the provider to set resource requests for the provider's deployment resource).

{{- end }}
{{- end }}
4 changes: 4 additions & 0 deletions hack/charts/cluster-api-operator/templates/control-plane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if hasKey (default (dict) $.Values.deploymentOverride) "controlPlane" }}
{{ .Values.deploymentOverride.controlPlane | toYaml | nindent 2 }}
{{- end }}
{{- end }}

Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if hasKey (default (dict) $.Values.deploymentOverride ) "coreCondition" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case for this manifest? Also, isn’t this a duplicate of templates/core.yaml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by duplicate? templates/core.yaml has the following:
https://github.com/kubernetes-sigs/cluster-api-operator/pull/525/files#diff-c73589d6ec69abbc84b0231a82d1fa536f3955e38026e4440db0b8e351295621R63

and I think we should avoid this default by just adding a default values to the values.yaml file.

{{ .Values.deploymentOverride.coreCondition| toYaml | nindent 2 }}
{{- end }}

{{- end }}
3 changes: 3 additions & 0 deletions hack/charts/cluster-api-operator/templates/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ spec:
{{- end }}
{{- end }}
{{- end }}

{{- if hasKey (default (dict) $.Values.deploymentOverride ) "infraCondition" }}
{{ .Values.deploymentOverride.infraCondition | toYaml | nindent 2 }}
{{- end }}
{{- end }}

3 changes: 3 additions & 0 deletions hack/charts/cluster-api-operator/templates/infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ spec:
{{- include "recursivePrinter" $.Values.additionalDeployments | indent 2 }}
{{- end }}
{{- end }}
{{- if hasKey (default (dict) $.Values.deploymentOverride ) "infrastructure" }}
{{ .Values.deploymentOverride.infrastructure | toYaml | nindent 2 }}
{{- end }}
{{- end }}
32 changes: 32 additions & 0 deletions test/e2e/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,36 @@ 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)))
})
})
128 changes: 128 additions & 0 deletions test/e2e/resources/addon-and-infra-override.yaml
Original file line number Diff line number Diff line change
@@ -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
123 changes: 123 additions & 0 deletions test/e2e/resources/only-infra-and-addon-override.yaml
Original file line number Diff line number Diff line change
@@ -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