diff --git a/component/main.jsonnet b/component/main.jsonnet index 59cfc99..b602758 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -1,6 +1,6 @@ // main template for rollout-operator +local alertpatching = import 'lib/alert-patching.libsonnet'; local kap = import 'lib/kapitan.libjsonnet'; -local kube = import 'lib/kube.libjsonnet'; local prom = import 'lib/prom.libsonnet'; local inv = kap.inventory(); @@ -31,8 +31,11 @@ local prometheusRules = prom.generateRules('rollout-operator', { 'rollout-operat }, }; +local has_monitoring = std.member(inv.applications, 'prometheus') || std.member(inv.applications, 'openshift4-monitoring'); +local has_alerts = std.length(params.alerts.rules) > 0; + // Define outputs below { '00_namespace': namespace, - [if params.monitoring then '20_prometheus_rule']: prometheusRules, + [if params.monitoring && has_monitoring && has_alerts then '20_prometheus_rule']: prometheusRules, } diff --git a/tests/defaults.yml b/tests/defaults.yml index 109db87..40241f1 100644 --- a/tests/defaults.yml +++ b/tests/defaults.yml @@ -1,9 +1,15 @@ +applications: + - prometheus + parameters: kapitan: dependencies: - type: https - source: https://raw.githubusercontent.com/appuio/component-openshift4-monitoring/master/lib/openshift4-monitoring-alert-patching.libsonnet + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus-alert-patching.libsonnet output_path: vendor/lib/alert-patching.libsonnet - type: https - source: https://raw.githubusercontent.com/appuio/component-openshift4-monitoring/master/lib/openshift4-monitoring-prom.libsonnet + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus-prom.libsonnet output_path: vendor/lib/prom.libsonnet + - type: https + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus.libsonnet + output_path: vendor/lib/prometheus.libsonnet diff --git a/tests/golden/defaults/rollout-operator/rollout-operator/20_prometheus_rule.yaml b/tests/golden/defaults/rollout-operator/rollout-operator/20_prometheus_rule.yaml index 71b8a49..9a48d12 100644 --- a/tests/golden/defaults/rollout-operator/rollout-operator/20_prometheus_rule.yaml +++ b/tests/golden/defaults/rollout-operator/rollout-operator/20_prometheus_rule.yaml @@ -4,6 +4,7 @@ metadata: labels: app.kubernetes.io/managed-by: commodore app.kubernetes.io/name: rollout-operator + monitoring.syn.tools/enabled: 'true' name: rollout-operator name: rollout-operator namespace: syn-rollout-operator diff --git a/tests/openshift.yml b/tests/openshift.yml index f80f3d0..f7fbfc7 100644 --- a/tests/openshift.yml +++ b/tests/openshift.yml @@ -1,3 +1,6 @@ +applications: + - openshift4-monitoring + parameters: kapitan: dependencies: