diff --git a/deploy/operator.yaml b/deploy/operator.yaml index 6f4559c4..1d46c0dd 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -33,6 +33,8 @@ spec: env: - name: TEMPLATE_PATH value: /usr/local/bin/templates + - name: MONITORING_KEY + value: middleware - name: WATCH_NAMESPACE valueFrom: fieldRef: diff --git a/pkg/controller/applicationmonitoring/templateHelper.go b/pkg/controller/applicationmonitoring/templateHelper.go index 59aa6db0..dc6d5083 100644 --- a/pkg/controller/applicationmonitoring/templateHelper.go +++ b/pkg/controller/applicationmonitoring/templateHelper.go @@ -51,6 +51,7 @@ type Parameters struct { AlertManagerRouteName string GrafanaServiceMonitorName string PrometheusServiceMonitorName string + MonitoringKey string } type TemplateHelper struct { @@ -80,13 +81,19 @@ func newTemplateHelper(cr *applicationmonitoring.ApplicationMonitoring) *Templat AlertManagerRouteName: AlertManagerRouteName, GrafanaServiceMonitorName: GrafanaServiceMonitorName, PrometheusServiceMonitorName: PrometheusServiceMonitorName, + MonitoringKey: "middleware", } - templatePath := os.Getenv("TEMPLATE_PATH") - if templatePath == "" { + templatePath, exists := os.LookupEnv("TEMPLATE_PATH") + if !exists { templatePath = "./templates" } + monitoringKey, exists := os.LookupEnv("MONITORING_KEY") + if exists { + param.MonitoringKey = monitoringKey + } + return &TemplateHelper{ Parameters: param, TemplatePath: templatePath, diff --git a/templates/grafana.yaml b/templates/grafana.yaml index d27fe04d..85ddda4f 100644 --- a/templates/grafana.yaml +++ b/templates/grafana.yaml @@ -5,3 +5,6 @@ metadata: namespace: {{ .Namespace }} spec: prometheusUrl: "http://prometheus-service:9090" + dashboardNamespaceSelector: + matchLabels: + monitoring-key: {{ .MonitoringKey }}