diff --git a/component/config.jsonnet b/component/config.jsonnet index c7c9fc99..c3c59ca6 100644 --- a/component/config.jsonnet +++ b/component/config.jsonnet @@ -1,9 +1,10 @@ local kap = import 'lib/kapitan.libjsonnet'; local kube = import 'lib/kube.libjsonnet'; +local prometheus = import 'lib/prometheus.libsonnet'; local inv = kap.inventory(); local params = inv.parameters.argocd; -local namespace = kube.Namespace(params.namespace) { +local ns_metadata = { metadata+: { labels+: { SYNMonitoring: 'main', @@ -13,6 +14,13 @@ local namespace = kube.Namespace(params.namespace) { }, }; +local namespace = + if std.member(inv.applications, 'prometheus') then + prometheus.RegisterNamespace(kube.Namespace(params.namespace)) + ns_metadata + else + kube.Namespace(params.namespace) + ns_metadata +; + local config = [ kube.ConfigMap('argocd-cm') { data: { diff --git a/component/monitoring.libsonnet b/component/monitoring.libsonnet index 376d0114..e5eb2b8e 100644 --- a/component/monitoring.libsonnet +++ b/component/monitoring.libsonnet @@ -1,5 +1,6 @@ local kap = import 'lib/kapitan.libjsonnet'; local kube = import 'lib/kube.libjsonnet'; +local prometheus = import 'lib/prometheus.libsonnet'; local inv = kap.inventory(); local params = inv.parameters.argocd; @@ -96,9 +97,15 @@ local grafana_dashboard = }, }; +local promEnable = function(obj) + if std.member(inv.applications, 'prometheus') then + prometheus.Enable(obj) + else obj +; + [ - serviceMonitor('argocd-metrics'), - serviceMonitor('argocd-server-metrics'), - serviceMonitor('argocd-repo-server'), - alert_rules, + promEnable(serviceMonitor('argocd-metrics')), + promEnable(serviceMonitor('argocd-server-metrics')), + promEnable(serviceMonitor('argocd-repo-server')), + promEnable(alert_rules), ] + if params.monitoring.dashboards then [ grafana_dashboard ] else [] diff --git a/tests/defaults.yml b/tests/defaults.yml index 75927194..59c62216 100644 --- a/tests/defaults.yml +++ b/tests/defaults.yml @@ -1,5 +1,17 @@ +applications: + - prometheus + parameters: + kapitan: + dependencies: + - type: https + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus.libsonnet + output_path: vendor/lib/prometheus.libsonnet + secret_management: vault_role: test vault_auth_mount_path: auth/lieutenant vault_addr: test.syn.tools + + prometheus: + defaultInstance: infra diff --git a/tests/golden/defaults/argocd/argocd/10_config/00_namespace.yaml b/tests/golden/defaults/argocd/argocd/10_config/00_namespace.yaml index cf5f662a..acf5d57c 100644 --- a/tests/golden/defaults/argocd/argocd/10_config/00_namespace.yaml +++ b/tests/golden/defaults/argocd/argocd/10_config/00_namespace.yaml @@ -5,6 +5,7 @@ metadata: labels: SYNMonitoring: main app.kubernetes.io/part-of: argocd + monitoring.syn.tools/infra: 'true' name: syn openshift.io/cluster-monitoring: 'true' name: syn diff --git a/tests/golden/defaults/argocd/argocd/10_config/20_monitoring.yaml b/tests/golden/defaults/argocd/argocd/10_config/20_monitoring.yaml index b614fc2e..c229c7ab 100644 --- a/tests/golden/defaults/argocd/argocd/10_config/20_monitoring.yaml +++ b/tests/golden/defaults/argocd/argocd/10_config/20_monitoring.yaml @@ -5,6 +5,7 @@ metadata: labels: app.kubernetes.io/name: argocd-metrics app.kubernetes.io/part-of: argocd + monitoring.syn.tools/enabled: 'true' name: argocd-metrics name: argocd-metrics namespace: syn @@ -23,6 +24,7 @@ metadata: labels: app.kubernetes.io/name: argocd-server-metrics app.kubernetes.io/part-of: argocd + monitoring.syn.tools/enabled: 'true' name: argocd-server-metrics name: argocd-server-metrics namespace: syn @@ -41,6 +43,7 @@ metadata: labels: app.kubernetes.io/name: argocd-repo-server app.kubernetes.io/part-of: argocd + monitoring.syn.tools/enabled: 'true' name: argocd-repo-server name: argocd-repo-server namespace: syn @@ -58,6 +61,7 @@ metadata: annotations: {} labels: cluster_id: c-green-test-1234 + monitoring.syn.tools/enabled: 'true' name: argocd prometheus: platform role: alert-rules diff --git a/tests/golden/openshift/argocd/argocd/10_config/00_namespace.yaml b/tests/golden/openshift/argocd/argocd/10_config/00_namespace.yaml index cf5f662a..acf5d57c 100644 --- a/tests/golden/openshift/argocd/argocd/10_config/00_namespace.yaml +++ b/tests/golden/openshift/argocd/argocd/10_config/00_namespace.yaml @@ -5,6 +5,7 @@ metadata: labels: SYNMonitoring: main app.kubernetes.io/part-of: argocd + monitoring.syn.tools/infra: 'true' name: syn openshift.io/cluster-monitoring: 'true' name: syn diff --git a/tests/golden/openshift/argocd/argocd/10_config/20_monitoring.yaml b/tests/golden/openshift/argocd/argocd/10_config/20_monitoring.yaml index b614fc2e..c229c7ab 100644 --- a/tests/golden/openshift/argocd/argocd/10_config/20_monitoring.yaml +++ b/tests/golden/openshift/argocd/argocd/10_config/20_monitoring.yaml @@ -5,6 +5,7 @@ metadata: labels: app.kubernetes.io/name: argocd-metrics app.kubernetes.io/part-of: argocd + monitoring.syn.tools/enabled: 'true' name: argocd-metrics name: argocd-metrics namespace: syn @@ -23,6 +24,7 @@ metadata: labels: app.kubernetes.io/name: argocd-server-metrics app.kubernetes.io/part-of: argocd + monitoring.syn.tools/enabled: 'true' name: argocd-server-metrics name: argocd-server-metrics namespace: syn @@ -41,6 +43,7 @@ metadata: labels: app.kubernetes.io/name: argocd-repo-server app.kubernetes.io/part-of: argocd + monitoring.syn.tools/enabled: 'true' name: argocd-repo-server name: argocd-repo-server namespace: syn @@ -58,6 +61,7 @@ metadata: annotations: {} labels: cluster_id: c-green-test-1234 + monitoring.syn.tools/enabled: 'true' name: argocd prometheus: platform role: alert-rules diff --git a/tests/openshift.yml b/tests/openshift.yml index 84d27f12..14cc7ae5 100644 --- a/tests/openshift.yml +++ b/tests/openshift.yml @@ -1,7 +1,19 @@ +applications: + - prometheus + parameters: + kapitan: + dependencies: + - type: https + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus.libsonnet + output_path: vendor/lib/prometheus.libsonnet + secret_management: vault_role: test vault_addr: test.syn.tools facts: distribution: openshift4 + + prometheus: + defaultInstance: infra