Skip to content

Commit

Permalink
Merge pull request #106 from projectsyn/add_missing_monitoring_labels
Browse files Browse the repository at this point in the history
Add monitoring labels to support component-prometheus
  • Loading branch information
TheBigLee authored Sep 22, 2022
2 parents f0a2097 + 8c3581d commit 950c56f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ KUBENT_ARGS ?= -c=false --helm2=false --helm3=false -e
KUBENT_IMAGE ?= docker.io/projectsyn/kubent:latest
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)

instance ?= defaults
instance ?= v2
test_instances = tests/v1.yml tests/v2.yml
24 changes: 19 additions & 5 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -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.backup_k8up;

Expand Down Expand Up @@ -40,12 +41,25 @@ local monitoring_labels =

local want_global_config = params.global_backup_config.enabled && params.global_backup_config.s3_endpoint != null;

local namespace =
if params.monitoring_enabled && std.member(inv.applications, 'prometheus') then
prometheus.RegisterNamespace(kube.Namespace(params.namespace)) {
metadata+: {
labels+: monitoring_labels,
},
}
else if params.monitoring_enabled then
kube.Namespace(params.namespace) {
metadata+: {
labels+: monitoring_labels,
},
}
else
kube.Namespace(params.namespace)
;

{
'00_namespace': kube.Namespace(params.namespace) {
metadata+: {
labels+: monitoring_labels,
},
},
'00_namespace': namespace,
[if want_global_config then '10_global_s3_credentials']:
credentials_secret(params.global_backup_config.s3_credentials),
[if want_global_config then '10_global_s3restore_credentials']:
Expand Down
18 changes: 17 additions & 1 deletion component/monitoring.jsonnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local com = import 'lib/commodore.libjsonnet';
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.backup_k8up;

Expand Down Expand Up @@ -87,4 +89,18 @@ local alert_rules = com.namespaced(params.namespace, {
},
});

[ alert_rules, service_monitor ]
local final_alert_rules =
if std.member(inv.applications, 'prometheus') then
prometheus.Enable(alert_rules)
else
alert_rules
;

local final_service_monitor =
if std.member(inv.applications, 'prometheus') then
prometheus.Enable(service_monitor)
else
service_monitor
;

[ final_alert_rules, final_service_monitor ]
1 change: 1 addition & 0 deletions tests/golden/v2/backup-k8up/backup-k8up/00_namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ metadata:
annotations: {}
labels:
SYNMonitoring: main
monitoring.syn.tools/infra: 'true'
name: syn-backup-k8up
name: syn-backup-k8up
2 changes: 2 additions & 0 deletions tests/golden/v2/backup-k8up/backup-k8up/30_monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
monitoring.syn.tools/enabled: 'true'
prometheus: main
role: alert-rules
name: k8up
Expand Down Expand Up @@ -120,6 +121,7 @@ metadata:
labels:
app.kubernetes.io/instance: k8up
app.kubernetes.io/name: k8up
monitoring.syn.tools/enabled: 'true'
prometheus: main
name: k8up-operator
namespace: syn-backup-k8up
Expand Down
13 changes: 12 additions & 1 deletion tests/v2.yml
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# using defaults
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

prometheus:
defaultInstance: infra

0 comments on commit 950c56f

Please sign in to comment.