diff --git a/charts/prometheus-operator.yaml b/charts/prometheus-operator.yaml index 0674435e2c..3a0ad5cb0a 100644 --- a/charts/prometheus-operator.yaml +++ b/charts/prometheus-operator.yaml @@ -9,7 +9,7 @@ commonLabels: alertmanager: alertmanagerSpec: image: - repository: '''{%- endraw -%}{{ build_image_name("alertmanager", False) }}{%- raw -%}''' + repository: '__image__(alertmanager)' nodeSelector: node-role.kubernetes.io/infra: '' @@ -24,6 +24,8 @@ alertmanager: operator: 'Exists' effect: 'NoSchedule' + replicas: '__var__(alertmanager.spec.deployment.replicas)' + storage: volumeClaimTemplate: spec: @@ -56,22 +58,22 @@ prometheusOperator: effect: 'NoSchedule' image: - repository: '{%- endraw -%}{{ build_image_name(\"prometheus-operator\", False) }}{%- raw -%}' + repository: '__image__(prometheus-operator)' configmapReloadImage: - repository: '{%- endraw -%}{{ build_image_name("configmap-reload", False) }}{%- raw -%}' + repository: '__image__(configmap-reload)' prometheusConfigReloaderImage: - repository: '{%- endraw -%}{{ build_image_name("prometheus-config-reloader", False) }}{%- raw -%}' + repository: '__image__(prometheus-config-reloader)' hyperkubeImage: - repository: '''{%- endraw -%}{{ build_image_name("hyperkube", False) }}{%- raw -%}''' + repository: '__image__(hyperkube)' prometheus: prometheusSpec: image: - repository: '''{%- endraw -%}{{ build_image_name("prometheus", False) }}{%- raw -%}''' + repository: '__image__(prometheus)' tolerations: - key: 'node-role.kubernetes.io/bootstrap' @@ -81,6 +83,8 @@ prometheus: operator: 'Exists' effect: 'NoSchedule' + replicas: '__var__(prometheus.spec.deployment.replicas)' + nodeSelector: node-role.kubernetes.io/infra: '' @@ -102,10 +106,10 @@ grafana: adminPassword: admin image: - repository: '{%- endraw -%}{{ build_image_name(\"grafana\", False) }}{%- raw -%}' + repository: '__image__(grafana)' sidecar: - image: '{%- endraw -%}{{ build_image_name(\"k8s-sidecar\", False) }}{%- raw -%}:0.1.20' + image: '__image__(k8s-sidecar):0.1.20' nodeSelector: node-role.kubernetes.io/infra: '' @@ -118,6 +122,9 @@ grafana: operator: 'Exists' effect: 'NoSchedule' + replicas: '__var__(grafana.spec.deployment.replicas)' + + ingress: enabled: true annotations: @@ -140,7 +147,7 @@ grafana: kube-state-metrics: image: - repository: '{%- endraw -%}{{ build_image_name(\"kube-state-metrics\", False) }}{%- raw -%}' + repository: '__image__(kube-state-metrics)' nodeSelector: node-role.kubernetes.io/infra: '' @@ -156,7 +163,7 @@ kube-state-metrics: prometheus-node-exporter: image: - repository: '{%- endraw -%}{{ build_image_name(\"node-exporter\", False) }}{%- raw -%}' + repository: '__image__(node-exporter)' kubeEtcd: diff --git a/charts/render.py b/charts/render.py index 8833e93ff0..77fbc101bc 100755 --- a/charts/render.py +++ b/charts/render.py @@ -16,9 +16,18 @@ `app.kubernetes.io/managed-by` to `salt`, and copy any `app` and `component` fields to the canonical `app.kubernetes.io/name` and `app.kubernetes.io/component` fields +- Replace YAML-safe special strings (used in Helm values definitions) with the + appropriate Jinja syntax. Supports: + - "__var__()", to replace with "{{ }}" (useful when + retrieving variables from service configuration ConfigMaps) + - "__image__()", to replace with + "{{ build_image_name("", False) }}" + - "__full_image__()", to replace with + "{{ build_image_name("") }}" ''' import argparse +import io import re import sys import subprocess @@ -28,18 +37,18 @@ from yaml.representer import SafeRepresenter -START_BLOCK = ''' +START_BLOCK = """ #!jinja | metalk8s_kubernetes -{{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}} +{{%- from "metalk8s/repo/macro.sls" import build_image_name with context %}} {configlines} {{% raw %}} -''' +""" -END_BLOCK = ''' +END_BLOCK = """ {% endraw %} -''' +""" def fixup_metadata(namespace, doc): @@ -117,6 +126,31 @@ def keep_doc(doc): return True +def replace_magic_strings(rendered_yaml): + # Handle __var__ + result = re.sub( + r'__var__\((?P[\w\-_]+(?:\.[\w\-_]+)*)\)', + r'{% endraw -%}{{ \g }}{%- raw %}', + rendered_yaml, + ) + + # Handle __image__ + result = re.sub( + r'__image__\((?P[\w\-]+)\)', + r'{% endraw -%}{{ build_image_name("\g", False) }}{%- raw %}', + result, + ) + + # Handle __full_image__ (include version tag in the rendered name) + result = re.sub( + r'__full_image__\((?P[\w\-]+)\)', + r'{% endraw -%}{{ build_image_name("\g") }}{%- raw %}', + result, + ) + + return result + + def main(): parser = argparse.ArgumentParser() parser.add_argument('name', help="Denotes the name of the chart") @@ -175,13 +209,17 @@ def main(): ) sys.stdout.write('\n') + stream = io.StringIO() yaml.safe_dump_all( (fixup(doc) for doc in yaml.safe_load_all(template) if keep_doc(doc)), - sys.stdout, + stream, default_flow_style=False, ) + stream.seek(0) + + sys.stdout.write(replace_magic_strings(stream.read())) sys.stdout.write(END_BLOCK)