From c2f0dd4cd369bd660ba3f5c89cd9499f19ef7ec6 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Mon, 17 May 2021 12:05:47 +0200 Subject: [PATCH] fix: allow dashes in chart names for grafana dashboards --- charts/kubezero-metrics/sync_grafana_dashboards.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/charts/kubezero-metrics/sync_grafana_dashboards.py b/charts/kubezero-metrics/sync_grafana_dashboards.py index 4280c00e..232c0535 100755 --- a/charts/kubezero-metrics/sync_grafana_dashboards.py +++ b/charts/kubezero-metrics/sync_grafana_dashboards.py @@ -34,11 +34,17 @@ with open(config_file, 'r') as yaml_contents: config = yaml.safe_load(yaml_contents.read()) +configmap = '' if 'condition' in config: - configmap = '''{{- if %(condition)s }} + # use index function to make go template happy if '-' in names + if '-' in config['condition']: + tokens = config['condition'].split('.') + configmap = '''{{- if index .Values %(condition)s }} +''' % {'condition': ' '.join(f'"{w}"' for w in tokens[2:])} + + else: + configmap = '''{{- if %(condition)s }} ''' % config -else: - configmap = '' # Base configmap for KubeZero configmap += '''apiVersion: v1