diff --git a/jsonnet/kube-prometheus/alertmanager/alertmanager.libsonnet b/jsonnet/kube-prometheus/alertmanager/alertmanager.libsonnet index af9bf85463d5672b5157feb8a069fc1ed5727c6e..4b091e9ae6e3d92c20317ed597ecd1e85b585f45 100644 --- a/jsonnet/kube-prometheus/alertmanager/alertmanager.libsonnet +++ b/jsonnet/kube-prometheus/alertmanager/alertmanager.libsonnet @@ -1,163 +1,163 @@ -{ - _config+:: { - namespace: 'default', - - versions+:: { - alertmanager: 'v0.21.0', - }, - - imageRepos+:: { - alertmanager: 'quay.io/prometheus/alertmanager', +local defaults = { + local defaults = self, + namespace: error 'must provide namespace', + image: error 'must provide image', + version: error 'must provide version', + resources: {}, + commonLabels:: { + 'app.kubernetes.io/name': 'alertmanager', + 'app.kubernetes.io/version': defaults.version, + 'app.kubernetes.io/component': 'alert-router', + 'app.kubernetes.io/part-of': 'kube-prometheus', + }, + selectorLabels:: { + [labelName]: defaults.commonLabels[labelName] + for labelName in std.objectFields(defaults.commonLabels) + if !std.setMember(labelName, ['app.kubernetes.io/version']) + }, + name: error 'must provide name', + config: { + global: { + resolve_timeout: '5m', }, - - alertmanager+:: { - name: 'main', - config: { - global: { - resolve_timeout: '5m', - }, - inhibit_rules: [{ - source_match: { - severity: 'critical', - }, - target_match_re: { - severity: 'warning|info', - }, - equal: ['namespace', 'alertname'], - }, { - source_match: { - severity: 'warning', - }, - target_match_re: { - severity: 'info', - }, - equal: ['namespace', 'alertname'], - }], - route: { - group_by: ['namespace'], - group_wait: '30s', - group_interval: '5m', - repeat_interval: '12h', - receiver: 'Default', - routes: [ - { receiver: 'Watchdog', match: { alertname: 'Watchdog' } }, - { receiver: 'Critical', match: { severity: 'critical' } }, - ], - }, - receivers: [ - { name: 'Default' }, - { name: 'Watchdog' }, - { name: 'Critical' }, - ], + inhibit_rules: [{ + source_match: { + severity: 'critical', }, - replicas: 3, - labels: { - 'app.kubernetes.io/name': 'alertmanager', - 'app.kubernetes.io/version': $._config.versions.alertmanager, - 'app.kubernetes.io/component': 'alert-router', - 'app.kubernetes.io/part-of': 'kube-prometheus', + target_match_re: { + severity: 'warning|info', }, - selectorLabels: { - [labelName]: $._config.alertmanager.labels[labelName] - for labelName in std.objectFields($._config.alertmanager.labels) - if !std.setMember(labelName, ['app.kubernetes.io/version']) + equal: ['namespace', 'alertname'], + }, { + source_match: { + severity: 'warning', }, + target_match_re: { + severity: 'info', + }, + equal: ['namespace', 'alertname'], + }], + route: { + group_by: ['namespace'], + group_wait: '30s', + group_interval: '5m', + repeat_interval: '12h', + receiver: 'Default', + routes: [ + { receiver: 'Watchdog', match: { alertname: 'Watchdog' } }, + { receiver: 'Critical', match: { severity: 'critical' } }, + ], }, + receivers: [ + { name: 'Default' }, + { name: 'Watchdog' }, + { name: 'Critical' }, + ], }, + replicas: 3, +}; - alertmanager+:: { - secret: { - apiVersion: 'v1', - kind: 'Secret', - type: 'Opaque', - metadata: { - name: 'alertmanager-' + $._config.alertmanager.name, - namespace: $._config.namespace, - labels: { alertmanager: $._config.alertmanager.name } + $._config.alertmanager.labels, - }, - stringData: { - 'alertmanager.yaml': if std.type($._config.alertmanager.config) == 'object' - then - std.manifestYamlDoc($._config.alertmanager.config) - else - $._config.alertmanager.config, - }, + + + +function(params) { + local am = self, + config:: defaults + params, + // Safety check + assert std.isObject(am.config.resources), + + secret: { + apiVersion: 'v1', + kind: 'Secret', + type: 'Opaque', + metadata: { + name: 'alertmanager-' + am.config.name, + namespace: am.config.namespace, + labels: { alertmanager: am.config.name } + am.config.commonLabels, }, + stringData: { + 'alertmanager.yaml': if std.type(am.config.config) == 'object' + then + std.manifestYamlDoc(am.config.config) + else + am.config.config, + }, + }, - serviceAccount: { - apiVersion: 'v1', - kind: 'ServiceAccount', - metadata: { - name: 'alertmanager-' + $._config.alertmanager.name, - namespace: $._config.namespace, - labels: { alertmanager: $._config.alertmanager.name } + $._config.alertmanager.labels, - }, + serviceAccount: { + apiVersion: 'v1', + kind: 'ServiceAccount', + metadata: { + name: 'alertmanager-' + am.config.name, + namespace: am.config.namespace, + labels: { alertmanager: am.config.name } + am.config.commonLabels, }, + }, - service: { - apiVersion: 'v1', - kind: 'Service', - metadata: { - name: 'alertmanager-' + $._config.alertmanager.name, - namespace: $._config.namespace, - labels: { alertmanager: $._config.alertmanager.name } + $._config.alertmanager.labels, - }, - spec: { - ports: [ - { name: 'web', targetPort: 'web', port: 9093 }, - ], - selector: { - app: 'alertmanager', - alertmanager: $._config.alertmanager.name, - } + $._config.alertmanager.selectorLabels, - sessionAffinity: 'ClientIP', - }, + service: { + apiVersion: 'v1', + kind: 'Service', + metadata: { + name: 'alertmanager-' + am.config.name, + namespace: am.config.namespace, + labels: { alertmanager: am.config.name } + am.config.commonLabels, + }, + spec: { + ports: [ + { name: 'web', targetPort: 'web', port: 9093 }, + ], + selector: { + app: 'alertmanager', + alertmanager: am.config.name, + } + am.config.selectorLabels, + sessionAffinity: 'ClientIP', }, + }, - serviceMonitor: { - apiVersion: 'monitoring.coreos.com/v1', - kind: 'ServiceMonitor', - metadata: { - name: 'alertmanager', - namespace: $._config.namespace, - labels: $._config.alertmanager.labels, - }, - spec: { - selector: { - matchLabels: { - alertmanager: $._config.alertmanager.name, - } + $._config.alertmanager.selectorLabels, - }, - endpoints: [ - { port: 'web', interval: '30s' }, - ], + serviceMonitor: { + apiVersion: 'monitoring.coreos.com/v1', + kind: 'ServiceMonitor', + metadata: { + name: 'alertmanager', + namespace: am.config.namespace, + labels: am.config.commonLabels, + }, + spec: { + selector: { + matchLabels: { + alertmanager: am.config.name, + } + am.config.selectorLabels, }, + endpoints: [ + { port: 'web', interval: '30s' }, + ], }, + }, - alertmanager: { - apiVersion: 'monitoring.coreos.com/v1', - kind: 'Alertmanager', - metadata: { - name: $._config.alertmanager.name, - namespace: $._config.namespace, - labels: { - alertmanager: $._config.alertmanager.name, - } + $._config.alertmanager.labels, + alertmanager: { + apiVersion: 'monitoring.coreos.com/v1', + kind: 'Alertmanager', + metadata: { + name: am.config.name, + namespace: am.config.namespace, + labels: { + alertmanager: am.config.name, + } + am.config.commonLabels, + }, + spec: { + replicas: am.config.replicas, + version: am.config.version, + image: am.config.image, + podMetadata: { + labels: am.config.commonLabels, }, - spec: { - replicas: $._config.alertmanager.replicas, - version: $._config.versions.alertmanager, - image: $._config.imageRepos.alertmanager + ':' + $._config.versions.alertmanager, - podMetadata: { - labels: $._config.alertmanager.labels, - }, - nodeSelector: { 'kubernetes.io/os': 'linux' }, - serviceAccountName: 'alertmanager-' + $._config.alertmanager.name, - securityContext: { - runAsUser: 1000, - runAsNonRoot: true, - fsGroup: 2000, - }, + resources: am.config.resources, + nodeSelector: { 'kubernetes.io/os': 'linux' }, + serviceAccountName: 'alertmanager-' + am.config.name, + securityContext: { + runAsUser: 1000, + runAsNonRoot: true, + fsGroup: 2000, }, }, }, diff --git a/jsonnet/kube-prometheus/kube-prometheus.libsonnet b/jsonnet/kube-prometheus/kube-prometheus.libsonnet index daab5bcc5d62ef45549dd9c7924e1d66d8804d5d..67bea5a8c9585811ab95722ac0ebe4ec479348a1 100644 --- a/jsonnet/kube-prometheus/kube-prometheus.libsonnet +++ b/jsonnet/kube-prometheus/kube-prometheus.libsonnet @@ -1,13 +1,13 @@ local kubeRbacProxyContainer = import './kube-rbac-proxy/containerMixin.libsonnet'; local nodeExporter = import './node-exporter/node-exporter.libsonnet'; +local alertmanager = import './alertmanager/alertmanager.libsonnet'; (import 'github.com/brancz/kubernetes-grafana/grafana/grafana.libsonnet') + (import './kube-state-metrics/kube-state-metrics.libsonnet') + (import 'github.com/kubernetes/kube-state-metrics/jsonnet/kube-state-metrics-mixin/mixin.libsonnet') + (import 'github.com/prometheus/node_exporter/docs/node-mixin/mixin.libsonnet') + (import './blackbox-exporter/blackbox-exporter.libsonnet') + -(import './alertmanager/alertmanager.libsonnet') + (import 'github.com/prometheus/alertmanager/doc/alertmanager-mixin/mixin.libsonnet') + (import 'github.com/prometheus-operator/prometheus-operator/jsonnet/prometheus-operator/prometheus-operator.libsonnet') + (import 'github.com/prometheus-operator/prometheus-operator/jsonnet/mixin/mixin.libsonnet') + @@ -23,6 +23,12 @@ local nodeExporter = import './node-exporter/node-exporter.libsonnet'; version: '1.0.1', image: 'quay.io/prometheus/node-exporter:v1.0.1', }), + alertmanager: alertmanager({ + name: 'main', + namespace: $._config.namespace, + version: '0.21.0', + image: 'quay.io/prometheus/alertmanager:v0.21.0', + }), kubePrometheus+:: { namespace: { apiVersion: 'v1', diff --git a/manifests/alertmanager-alertmanager.yaml b/manifests/alertmanager-alertmanager.yaml index be59749584e8b2fc35e409e9fd6dba251a71b5e3..351b7a0c9337b2fb9292cc8585633987a1538fc7 100644 --- a/manifests/alertmanager-alertmanager.yaml +++ b/manifests/alertmanager-alertmanager.yaml @@ -6,7 +6,7 @@ metadata: app.kubernetes.io/component: alert-router app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus - app.kubernetes.io/version: v0.21.0 + app.kubernetes.io/version: 0.21.0 name: main namespace: monitoring spec: @@ -18,11 +18,12 @@ spec: app.kubernetes.io/component: alert-router app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus - app.kubernetes.io/version: v0.21.0 + app.kubernetes.io/version: 0.21.0 replicas: 3 + resources: {} securityContext: fsGroup: 2000 runAsNonRoot: true runAsUser: 1000 serviceAccountName: alertmanager-main - version: v0.21.0 + version: 0.21.0 diff --git a/manifests/alertmanager-secret.yaml b/manifests/alertmanager-secret.yaml index 9868057f9b92ca72463dd55441a7eb92147786c3..c6ffb204dcc25762bcdff6d14347eb0bf7bf2841 100644 --- a/manifests/alertmanager-secret.yaml +++ b/manifests/alertmanager-secret.yaml @@ -6,7 +6,7 @@ metadata: app.kubernetes.io/component: alert-router app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus - app.kubernetes.io/version: v0.21.0 + app.kubernetes.io/version: 0.21.0 name: alertmanager-main namespace: monitoring stringData: diff --git a/manifests/alertmanager-service.yaml b/manifests/alertmanager-service.yaml index f6cd073a4fd4255ec648b76d2daccc68e8bdf544..8c611f9f41fa51209b064c607fb63009cad8ab5d 100644 --- a/manifests/alertmanager-service.yaml +++ b/manifests/alertmanager-service.yaml @@ -6,7 +6,7 @@ metadata: app.kubernetes.io/component: alert-router app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus - app.kubernetes.io/version: v0.21.0 + app.kubernetes.io/version: 0.21.0 name: alertmanager-main namespace: monitoring spec: diff --git a/manifests/alertmanager-serviceAccount.yaml b/manifests/alertmanager-serviceAccount.yaml index 4403e398d80188c06dc27d542f6247786c10631c..5a645515f8f1e8d1cb8f92cae76c78f79e1916d2 100644 --- a/manifests/alertmanager-serviceAccount.yaml +++ b/manifests/alertmanager-serviceAccount.yaml @@ -6,6 +6,6 @@ metadata: app.kubernetes.io/component: alert-router app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus - app.kubernetes.io/version: v0.21.0 + app.kubernetes.io/version: 0.21.0 name: alertmanager-main namespace: monitoring diff --git a/manifests/alertmanager-serviceMonitor.yaml b/manifests/alertmanager-serviceMonitor.yaml index f6f22d86cf3ac64afbed12a5fd0b3b4143056e7a..6ff4570544c5bb3f37430d847e5bae6e268b0753 100644 --- a/manifests/alertmanager-serviceMonitor.yaml +++ b/manifests/alertmanager-serviceMonitor.yaml @@ -5,7 +5,7 @@ metadata: app.kubernetes.io/component: alert-router app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus - app.kubernetes.io/version: v0.21.0 + app.kubernetes.io/version: 0.21.0 name: alertmanager namespace: monitoring spec: