From 427b08be40b28902bed81a05eac34fa40f760545 Mon Sep 17 00:00:00 2001 From: Jens Schneider Date: Fri, 18 Feb 2022 18:17:27 +0100 Subject: [PATCH] Add another if statement in templates This supports having empty maps and lists in the default values.yaml. Consequently, as user could check the values.yaml for configuration options. Signed-off-by: Jens Schneider --- charts/extensions/Chart.yaml | 2 +- .../templates/extension-shoot-dns-service.yaml | 8 ++++++-- charts/extensions/templates/external-dns-management.yaml | 8 ++++++-- charts/extensions/templates/networking-calico.yaml | 8 ++++++-- charts/extensions/templates/networking-cilium.yaml | 8 ++++++-- charts/extensions/templates/os-gardenlinux.yaml | 8 ++++++-- charts/extensions/templates/os-ubuntu.yaml | 8 ++++++-- charts/extensions/templates/provider-alicloud.yaml | 8 ++++++-- charts/extensions/templates/provider-aws.yaml | 8 ++++++-- charts/extensions/templates/provider-azure.yaml | 8 ++++++-- charts/extensions/templates/provider-gcp.yaml | 8 ++++++-- charts/extensions/templates/provider-hcloud.yaml | 8 ++++++-- charts/extensions/templates/provider-openstack.yaml | 8 ++++++-- charts/extensions/templates/shoot-cert-service.yaml | 8 ++++++-- .../helmchart-import/import-gardener-extension-charts.py | 9 +++++++-- 15 files changed, 86 insertions(+), 29 deletions(-) diff --git a/charts/extensions/Chart.yaml b/charts/extensions/Chart.yaml index df1e94bc..ec6dd808 100644 --- a/charts/extensions/Chart.yaml +++ b/charts/extensions/Chart.yaml @@ -3,4 +3,4 @@ name: extensions description: A Helm chart for managing gardener extensions # This is the chart version. -version: 1.0.1 +version: 1.0.0 diff --git a/charts/extensions/templates/extension-shoot-dns-service.yaml b/charts/extensions/templates/extension-shoot-dns-service.yaml index 8064ca49..88587e51 100644 --- a/charts/extensions/templates/extension-shoot-dns-service.yaml +++ b/charts/extensions/templates/extension-shoot-dns-service.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.14.0 +{{- if (index .Values "extension-shoot-dns-service").values }} {{- toYaml (index .Values "extension-shoot-dns-service").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -23,5 +25,7 @@ spec: resources: - kind: Extension type: shoot-dns-service -{{- toYaml (index .Values "extension-shoot-dns-service").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "extension-shoot-dns-service").resources}} +{{- toYaml (index .Values "extension-shoot-dns-service").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/external-dns-management.yaml b/charts/extensions/templates/external-dns-management.yaml index a9f73fa1..f1a640d2 100644 --- a/charts/extensions/templates/external-dns-management.yaml +++ b/charts/extensions/templates/external-dns-management.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v0.11.4 +{{- if (index .Values "external-dns-management").values }} {{- toYaml (index .Values "external-dns-management").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -39,5 +41,7 @@ spec: type: netlify-dns - kind: DNSProvider type: infoblox-dns -{{- toYaml (index .Values "external-dns-management").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "external-dns-management").resources}} +{{- toYaml (index .Values "external-dns-management").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/networking-calico.yaml b/charts/extensions/templates/networking-calico.yaml index 28ddef82..5efe40f2 100644 --- a/charts/extensions/templates/networking-calico.yaml +++ b/charts/extensions/templates/networking-calico.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.19.0 +{{- if (index .Values "networking-calico").values }} {{- toYaml (index .Values "networking-calico").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -23,5 +25,7 @@ spec: resources: - kind: Network type: calico -{{- toYaml (index .Values "networking-calico").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "networking-calico").resources}} +{{- toYaml (index .Values "networking-calico").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/networking-cilium.yaml b/charts/extensions/templates/networking-cilium.yaml index 67e59a24..3ff580b8 100644 --- a/charts/extensions/templates/networking-cilium.yaml +++ b/charts/extensions/templates/networking-cilium.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.8.0 +{{- if (index .Values "networking-cilium").values }} {{- toYaml (index .Values "networking-cilium").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -23,5 +25,7 @@ spec: resources: - kind: Network type: cilium -{{- toYaml (index .Values "networking-cilium").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "networking-cilium").resources}} +{{- toYaml (index .Values "networking-cilium").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/os-gardenlinux.yaml b/charts/extensions/templates/os-gardenlinux.yaml index 780df503..0c30cf9d 100644 --- a/charts/extensions/templates/os-gardenlinux.yaml +++ b/charts/extensions/templates/os-gardenlinux.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v0.11.0 +{{- if (index .Values "os-gardenlinux").values }} {{- toYaml (index .Values "os-gardenlinux").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -23,5 +25,7 @@ spec: resources: - kind: OperatingSystemConfig type: gardenlinux -{{- toYaml (index .Values "os-gardenlinux").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "os-gardenlinux").resources}} +{{- toYaml (index .Values "os-gardenlinux").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/os-ubuntu.yaml b/charts/extensions/templates/os-ubuntu.yaml index 973ed916..77afe3b2 100644 --- a/charts/extensions/templates/os-ubuntu.yaml +++ b/charts/extensions/templates/os-ubuntu.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.13.0 +{{- if (index .Values "os-ubuntu").values }} {{- toYaml (index .Values "os-ubuntu").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -25,5 +27,7 @@ spec: type: ubuntu - kind: OperatingSystemConfig type: ubuntu-pro -{{- toYaml (index .Values "os-ubuntu").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "os-ubuntu").resources}} +{{- toYaml (index .Values "os-ubuntu").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/provider-alicloud.yaml b/charts/extensions/templates/provider-alicloud.yaml index bdee75cd..5b0fec1a 100644 --- a/charts/extensions/templates/provider-alicloud.yaml +++ b/charts/extensions/templates/provider-alicloud.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.32.0 +{{- if (index .Values "provider-alicloud").values }} {{- toYaml (index .Values "provider-alicloud").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -33,5 +35,7 @@ spec: type: alicloud - kind: Worker type: alicloud -{{- toYaml (index .Values "provider-alicloud").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "provider-alicloud").resources}} +{{- toYaml (index .Values "provider-alicloud").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/provider-aws.yaml b/charts/extensions/templates/provider-aws.yaml index b4f09731..fe72130c 100644 --- a/charts/extensions/templates/provider-aws.yaml +++ b/charts/extensions/templates/provider-aws.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.33.0 +{{- if (index .Values "provider-aws").values }} {{- toYaml (index .Values "provider-aws").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -35,5 +37,7 @@ spec: type: aws - kind: Worker type: aws -{{- toYaml (index .Values "provider-aws").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "provider-aws").resources}} +{{- toYaml (index .Values "provider-aws").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/provider-azure.yaml b/charts/extensions/templates/provider-azure.yaml index b0d59b49..69aead8e 100644 --- a/charts/extensions/templates/provider-azure.yaml +++ b/charts/extensions/templates/provider-azure.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.24.1 +{{- if (index .Values "provider-azure").values }} {{- toYaml (index .Values "provider-azure").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -33,5 +35,7 @@ spec: type: azure - kind: Worker type: azure -{{- toYaml (index .Values "provider-azure").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "provider-azure").resources}} +{{- toYaml (index .Values "provider-azure").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/provider-gcp.yaml b/charts/extensions/templates/provider-gcp.yaml index f8095a21..d5e7077b 100644 --- a/charts/extensions/templates/provider-gcp.yaml +++ b/charts/extensions/templates/provider-gcp.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.20.0 +{{- if (index .Values "provider-gcp").values }} {{- toYaml (index .Values "provider-gcp").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -35,5 +37,7 @@ spec: type: gcp - kind: Worker type: gcp -{{- toYaml (index .Values "provider-gcp").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "provider-gcp").resources}} +{{- toYaml (index .Values "provider-gcp").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/provider-hcloud.yaml b/charts/extensions/templates/provider-hcloud.yaml index e0b9ee91..5321aa63 100644 --- a/charts/extensions/templates/provider-hcloud.yaml +++ b/charts/extensions/templates/provider-hcloud.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v0.4.8 +{{- if (index .Values "provider-hcloud").values }} {{- toYaml (index .Values "provider-hcloud").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -27,5 +29,7 @@ spec: type: hcloud - kind: Worker type: hcloud -{{- toYaml (index .Values "provider-hcloud").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "provider-hcloud").resources}} +{{- toYaml (index .Values "provider-hcloud").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/provider-openstack.yaml b/charts/extensions/templates/provider-openstack.yaml index f08bb830..d8bccc15 100644 --- a/charts/extensions/templates/provider-openstack.yaml +++ b/charts/extensions/templates/provider-openstack.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.23.1 +{{- if (index .Values "provider-openstack").values }} {{- toYaml (index .Values "provider-openstack").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -33,5 +35,7 @@ spec: type: openstack - kind: Worker type: openstack -{{- toYaml (index .Values "provider-openstack").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "provider-openstack").resources}} +{{- toYaml (index .Values "provider-openstack").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/extensions/templates/shoot-cert-service.yaml b/charts/extensions/templates/shoot-cert-service.yaml index 55c4b86f..fb4485d8 100644 --- a/charts/extensions/templates/shoot-cert-service.yaml +++ b/charts/extensions/templates/shoot-cert-service.yaml @@ -10,7 +10,9 @@ providerConfig: values: image: tag: v1.18.0 +{{- if (index .Values "shoot-cert-service").values }} {{- toYaml (index .Values "shoot-cert-service").values | nindent 4 }} +{{- end }} --- apiVersion: core.gardener.cloud/v1beta1 kind: ControllerRegistration @@ -23,5 +25,7 @@ spec: resources: - kind: Extension type: shoot-cert-service -{{- toYaml (index .Values "shoot-cert-service").resources | nindent 4 }} -{{- end }} \ No newline at end of file +{{- if (index .Values "shoot-cert-service").resources}} +{{- toYaml (index .Values "shoot-cert-service").resources | nindent 2 }} +{{- end }} +{{- end }} diff --git a/hack/helmchart-import/import-gardener-extension-charts.py b/hack/helmchart-import/import-gardener-extension-charts.py index 04ec3f08..e1af3559 100644 --- a/hack/helmchart-import/import-gardener-extension-charts.py +++ b/hack/helmchart-import/import-gardener-extension-charts.py @@ -132,10 +132,15 @@ def import_charts(cfg, target_dir): with outf.open("a") as ofp: ofp.write("{{- if (index .Values " + '"' + cfg["name"] + '"' + ").enabled }}\n") yaml.dump(content[0], ofp) + ofp.write("{{- if (index .Values " + '"' + cfg["name"] + '"' + ").values }}\n") ofp.write("{{- toYaml (index .Values " + '"' + cfg["name"] + '"' + ").values | nindent 4 }}\n") + ofp.write("{{- end }}\n") + yaml.dump(content[1], ofp) - ofp.write("{{- toYaml (index .Values " + '"' + cfg["name"] + '"' + ").resources | nindent 4 }}\n") - ofp.write("{{- end }}") + ofp.write("{{- if (index .Values " + '"' + cfg["name"] + '"' + ").resources}}\n") + ofp.write("{{- toYaml (index .Values " + '"' + cfg["name"] + '"' + ").resources | nindent 2 }}\n") + ofp.write("{{- end }}\n") + ofp.write("{{- end }}\n") def write_values_yaml(config, target_dir):