Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Add another if statement in templates
Browse files Browse the repository at this point in the history
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 <schneider@23technologies.cloud>
  • Loading branch information
JensAc committed Feb 18, 2022
1 parent d6ba87e commit 427b08b
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 29 deletions.
2 changes: 1 addition & 1 deletion charts/extensions/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions charts/extensions/templates/extension-shoot-dns-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +25,7 @@ spec:
resources:
- kind: Extension
type: shoot-dns-service
{{- toYaml (index .Values "extension-shoot-dns-service").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "extension-shoot-dns-service").resources}}
{{- toYaml (index .Values "extension-shoot-dns-service").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/external-dns-management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,5 +41,7 @@ spec:
type: netlify-dns
- kind: DNSProvider
type: infoblox-dns
{{- toYaml (index .Values "external-dns-management").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "external-dns-management").resources}}
{{- toYaml (index .Values "external-dns-management").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/networking-calico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +25,7 @@ spec:
resources:
- kind: Network
type: calico
{{- toYaml (index .Values "networking-calico").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "networking-calico").resources}}
{{- toYaml (index .Values "networking-calico").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/networking-cilium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +25,7 @@ spec:
resources:
- kind: Network
type: cilium
{{- toYaml (index .Values "networking-cilium").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "networking-cilium").resources}}
{{- toYaml (index .Values "networking-cilium").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/os-gardenlinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +25,7 @@ spec:
resources:
- kind: OperatingSystemConfig
type: gardenlinux
{{- toYaml (index .Values "os-gardenlinux").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "os-gardenlinux").resources}}
{{- toYaml (index .Values "os-gardenlinux").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/os-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,5 +27,7 @@ spec:
type: ubuntu
- kind: OperatingSystemConfig
type: ubuntu-pro
{{- toYaml (index .Values "os-ubuntu").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "os-ubuntu").resources}}
{{- toYaml (index .Values "os-ubuntu").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/provider-alicloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,5 +35,7 @@ spec:
type: alicloud
- kind: Worker
type: alicloud
{{- toYaml (index .Values "provider-alicloud").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "provider-alicloud").resources}}
{{- toYaml (index .Values "provider-alicloud").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/provider-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,5 +37,7 @@ spec:
type: aws
- kind: Worker
type: aws
{{- toYaml (index .Values "provider-aws").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "provider-aws").resources}}
{{- toYaml (index .Values "provider-aws").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/provider-azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,5 +35,7 @@ spec:
type: azure
- kind: Worker
type: azure
{{- toYaml (index .Values "provider-azure").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "provider-azure").resources}}
{{- toYaml (index .Values "provider-azure").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/provider-gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,5 +37,7 @@ spec:
type: gcp
- kind: Worker
type: gcp
{{- toYaml (index .Values "provider-gcp").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "provider-gcp").resources}}
{{- toYaml (index .Values "provider-gcp").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/provider-hcloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,5 +29,7 @@ spec:
type: hcloud
- kind: Worker
type: hcloud
{{- toYaml (index .Values "provider-hcloud").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "provider-hcloud").resources}}
{{- toYaml (index .Values "provider-hcloud").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/provider-openstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,5 +35,7 @@ spec:
type: openstack
- kind: Worker
type: openstack
{{- toYaml (index .Values "provider-openstack").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "provider-openstack").resources}}
{{- toYaml (index .Values "provider-openstack").resources | nindent 2 }}
{{- end }}
{{- end }}
8 changes: 6 additions & 2 deletions charts/extensions/templates/shoot-cert-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +25,7 @@ spec:
resources:
- kind: Extension
type: shoot-cert-service
{{- toYaml (index .Values "shoot-cert-service").resources | nindent 4 }}
{{- end }}
{{- if (index .Values "shoot-cert-service").resources}}
{{- toYaml (index .Values "shoot-cert-service").resources | nindent 2 }}
{{- end }}
{{- end }}
9 changes: 7 additions & 2 deletions hack/helmchart-import/import-gardener-extension-charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 427b08b

Please sign in to comment.