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

Commit

Permalink
Change the templating interface for the user
Browse files Browse the repository at this point in the history
Now resources of kind: Extension can be enabled globally in
values.yaml, and all other resources are not configurable

Signed-off-by: Jens Schneider <schneider@23technologies.cloud>
  • Loading branch information
JensAc committed Feb 22, 2022
1 parent 71003a6 commit a730bdc
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 75 deletions.
3 changes: 0 additions & 3 deletions charts/extensions/templates/external-dns-management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,4 @@ spec:
type: netlify-dns
- kind: DNSProvider
type: infoblox-dns
{{- if (index .Values "external-dns-management").resources}}
{{- toYaml (index .Values "external-dns-management").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/networking-calico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ spec:
resources:
- kind: Network
type: calico
{{- if (index .Values "networking-calico").resources}}
{{- toYaml (index .Values "networking-calico").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/networking-cilium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ spec:
resources:
- kind: Network
type: cilium
{{- if (index .Values "networking-cilium").resources}}
{{- toYaml (index .Values "networking-cilium").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/os-gardenlinux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ spec:
resources:
- kind: OperatingSystemConfig
type: gardenlinux
{{- if (index .Values "os-gardenlinux").resources}}
{{- toYaml (index .Values "os-gardenlinux").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/os-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ spec:
type: ubuntu
- kind: OperatingSystemConfig
type: ubuntu-pro
{{- if (index .Values "os-ubuntu").resources}}
{{- toYaml (index .Values "os-ubuntu").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/provider-alicloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,4 @@ spec:
type: alicloud
- kind: Worker
type: alicloud
{{- if (index .Values "provider-alicloud").resources}}
{{- toYaml (index .Values "provider-alicloud").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/provider-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@ spec:
type: aws
- kind: Worker
type: aws
{{- if (index .Values "provider-aws").resources}}
{{- toYaml (index .Values "provider-aws").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/provider-azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,4 @@ spec:
type: azure
- kind: Worker
type: azure
{{- if (index .Values "provider-azure").resources}}
{{- toYaml (index .Values "provider-azure").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/provider-gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@ spec:
type: gcp
- kind: Worker
type: gcp
{{- if (index .Values "provider-gcp").resources}}
{{- toYaml (index .Values "provider-gcp").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/provider-hcloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ spec:
type: hcloud
- kind: Worker
type: hcloud
{{- if (index .Values "provider-hcloud").resources}}
{{- toYaml (index .Values "provider-hcloud").resources | nindent 2 }}
{{- end }}
{{- end }}
3 changes: 0 additions & 3 deletions charts/extensions/templates/provider-openstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,4 @@ spec:
type: openstack
- kind: Worker
type: openstack
{{- if (index .Values "provider-openstack").resources}}
{{- toYaml (index .Values "provider-openstack").resources | nindent 2 }}
{{- end }}
{{- end }}
4 changes: 1 addition & 3 deletions charts/extensions/templates/shoot-cert-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ spec:
resources:
- kind: Extension
type: shoot-cert-service
{{- if (index .Values "shoot-cert-service").resources}}
{{- toYaml (index .Values "shoot-cert-service").resources | nindent 2 }}
{{- end }}
globallyEnabled: {{ (index .Values "shoot-cert-service").globallyEnabled }}
{{- end }}
4 changes: 1 addition & 3 deletions charts/extensions/templates/shoot-dns-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ spec:
resources:
- kind: Extension
type: shoot-dns-service
{{- if (index .Values "shoot-dns-service").resources}}
{{- toYaml (index .Values "shoot-dns-service").resources | nindent 2 }}
{{- end }}
globallyEnabled: {{ (index .Values "shoot-dns-service").globallyEnabled }}
{{- end }}
15 changes: 2 additions & 13 deletions charts/extensions/values.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,54 @@
external-dns-management:
enabled: false
values: {}
resources: []

networking-calico:
enabled: false
values: {}
resources: []

networking-cilium:
enabled: false
values: {}
resources: []

os-gardenlinux:
enabled: false
values: {}
resources: []

os-ubuntu:
enabled: false
values: {}
resources: []

provider-alicloud:
enabled: false
values: {}
resources: []

provider-aws:
enabled: false
values: {}
resources: []

provider-azure:
enabled: false
values: {}
resources: []

provider-gcp:
enabled: false
values: {}
resources: []

provider-hcloud:
enabled: false
values: {}
resources: []

provider-openstack:
enabled: false
values: {}
resources: []

shoot-cert-service:
enabled: false
values: {}
resources: []
globallyEnabled: false

shoot-dns-service:
enabled: false
values: {}
resources: []
globallyEnabled: false

70 changes: 47 additions & 23 deletions hack/helmchart-import/import-gardener-extension-charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
import urllib
from urllib import request
from pathlib import Path
import semantic_version

import ruamel.yaml

yaml = ruamel.yaml.YAML()


# here go our importet helmcharts
target_dir = "charts/extensions/"

# make sure to rewrite the default values.yaml each time
outf = Path(target_dir + "values.yaml")
try:
outf.unlink()
except:
pass

# configure the charts you want to import here
# you need to define the package consiting of github-org/repo,
# the corresponding version, and src and dst directories
Expand Down Expand Up @@ -105,7 +114,7 @@ def import_charts(cfg, target_dir):
+ cfg["version"]
+ "/controller-registration.yaml",
]

# now let's fetch the yaml
for url in urls:
try:
Expand All @@ -117,7 +126,6 @@ def import_charts(cfg, target_dir):

# assume that we have to documents in our yaml, which is commonly the case for controller-registration.yamls
content = list(yaml.load_all(x))


# setup the path for our target chart
Path(target_dir + "templates/").mkdir(parents=True, exist_ok=True)
Expand All @@ -127,45 +135,61 @@ def import_charts(cfg, target_dir):
except:
pass

# define a dictionary for writing the default values.yaml file
default_values = {cfg["name"]: {"enabled": False, "values": {}}}

# write the target chart including templating
yaml.explicit_start = True
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(
"{{- toYaml (index .Values "
+ '"'
+ cfg["name"]
+ '"'
+ ").values | nindent 4 }}\n"
)
ofp.write("{{- end }}\n")

# if we have a kind: Extension in our resources, we want to be able to set this
# resource to globallyEnabled: true by helm templating
# Therefore, Add a helm template for this option
for resource in content[1]["spec"]["resources"]:
for k, v in dict(resource).items():
if (k, v) == ("kind", "Extension"):
resource["globallyEnabled"] = "HereOurHelmTemplateGoes"
default_values[cfg["name"]]["globallyEnabled"] = False
yaml.dump(content[1], ofp)
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):

# As we cannot write the helmtemplate with ruamel.yaml, we need to replace our previously
# inserted string "HereOurHelmTemplateGoes" with the actual template
with outf.open("r") as ofp:
content = ofp.read()
content = re.sub(
"HereOurHelmTemplateGoes",
"{{ (index .Values " + '"' + cfg["name"] + '"' + ").globallyEnabled }}",
content,
flags=re.M,
)

with outf.open("w") as ofp:
ofp.write(content)

# write the default values file
outf = Path(target_dir + "values.yaml")
try:
outf.unlink()
except:
pass
yaml.explicit_start = False
with outf.open("a") as ofp:
yaml.dump(default_values, ofp)
ofp.write("\n")

for cfg in config:
# write a basic values.yaml
content = {cfg["name"]: {"enabled": False, "values": {}, "resources": []}}
yaml.explicit_start = False
with outf.open("a") as ofp:
yaml.dump(content, ofp)
ofp.write("\n")


# call the import function for all elements in the config list
for cfg in config:
import_charts(cfg, target_dir)

# and write a starting point values.yaml
write_values_yaml(config,target_dir)

# lastly, increment the version number of the chart
chartf = Path(target_dir + "Chart.yaml")
chart = yaml.load(chartf)
Expand Down

0 comments on commit a730bdc

Please sign in to comment.