From 6eee0db52fa764141af339085dfc068af9dd6a81 Mon Sep 17 00:00:00 2001 From: clyang82 Date: Tue, 22 Sep 2020 15:18:08 +0800 Subject: [PATCH 1/6] support configure alertmanager Signed-off-by: clyang82 --- .../kube-thanos/kube-thanos-rule.libsonnet | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet index b7cb4c77..6aa7c974 100644 --- a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet @@ -183,4 +183,41 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; }, }, }, + + withAlertmanagers:: { + local tr = self, + config+:: { + rulesConfigMapName: error 'must provide rulesConfigMapName', + alertmanagersURL: error 'must provide alertmanagersURL', + }, + + statefulSet+: { + spec+: { + template+: { + spec+: { + containers: [ + if c.name == 'thanos-rule' then c { + args+: [ + '--alertmanagers.url=' + alertmanagerURL, + for alertmanagerURL in tr.config.alertmanagersURL + ] + [ + '--rule-file=/etc/thanos/rules/*.rules.yaml', + ], + volumeMounts+: [ + { name: 'rules-config', mountPath: '/etc/thanos/rules' }, + ], + } else c + for c in super.containers + ], + + local volume = k.apps.v1.statefulSet.mixin.spec.template.spec.volumesType, + volumes+: [ + volume.withName('rules-config') + + volume.mixin.configMap.withName(tr.config.rulesConfigMapName), + ], + }, + }, + }, + }, + }, } From a9f39efb02dbad8ca2bf7173c5ae17eb765c5560 Mon Sep 17 00:00:00 2001 From: clyang82 Date: Tue, 22 Sep 2020 16:16:41 +0800 Subject: [PATCH 2/6] read all yaml file in /etc/thanos/rules Signed-off-by: clyang82 --- jsonnet/kube-thanos/kube-thanos-rule.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet index 6aa7c974..6256099d 100644 --- a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet @@ -201,7 +201,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; '--alertmanagers.url=' + alertmanagerURL, for alertmanagerURL in tr.config.alertmanagersURL ] + [ - '--rule-file=/etc/thanos/rules/*.rules.yaml', + '--rule-file=/etc/thanos/rules/*.yaml', ], volumeMounts+: [ { name: 'rules-config', mountPath: '/etc/thanos/rules' }, From 23894fd005a7e0bf693f7bd9798abf89c005c092 Mon Sep 17 00:00:00 2001 From: clyang82 Date: Tue, 22 Sep 2020 18:14:42 +0800 Subject: [PATCH 3/6] support ruleFileKey Signed-off-by: clyang82 --- jsonnet/kube-thanos/kube-thanos-rule.libsonnet | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet index 6256099d..3004c624 100644 --- a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet @@ -187,7 +187,8 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; withAlertmanagers:: { local tr = self, config+:: { - rulesConfigMapName: error 'must provide rulesConfigMapName', + ruleConfigMapName: error 'must provide rulesConfigMapName', + ruleFileKey: error 'must provide ruleFileKey', alertmanagersURL: error 'must provide alertmanagersURL', }, @@ -201,7 +202,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; '--alertmanagers.url=' + alertmanagerURL, for alertmanagerURL in tr.config.alertmanagersURL ] + [ - '--rule-file=/etc/thanos/rules/*.yaml', + '--rule-file=/etc/thanos/rules/' + tr.config.ruleFileKey, ], volumeMounts+: [ { name: 'rules-config', mountPath: '/etc/thanos/rules' }, @@ -213,7 +214,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; local volume = k.apps.v1.statefulSet.mixin.spec.template.spec.volumesType, volumes+: [ volume.withName('rules-config') + - volume.mixin.configMap.withName(tr.config.rulesConfigMapName), + volume.mixin.configMap.withName(tr.config.ruleConfigMapName), ], }, }, From f08555a40d0d911be4ce5486a3a88161e3a021a2 Mon Sep 17 00:00:00 2001 From: clyang82 Date: Tue, 22 Sep 2020 18:30:26 +0800 Subject: [PATCH 4/6] Update message Signed-off-by: clyang82 --- jsonnet/kube-thanos/kube-thanos-rule.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet index 3004c624..d9a2f7d5 100644 --- a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet @@ -187,7 +187,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; withAlertmanagers:: { local tr = self, config+:: { - ruleConfigMapName: error 'must provide rulesConfigMapName', + ruleConfigMapName: error 'must provide ruleConfigMapName', ruleFileKey: error 'must provide ruleFileKey', alertmanagersURL: error 'must provide alertmanagersURL', }, From 84a4bfba0d3a706212e87b4446d3b48d005346b4 Mon Sep 17 00:00:00 2001 From: clyang82 Date: Wed, 23 Sep 2020 15:15:54 +0800 Subject: [PATCH 5/6] separate alertmanager with rules Signed-off-by: clyang82 --- .../kube-thanos/kube-thanos-rule.libsonnet | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet index d9a2f7d5..ab98519d 100644 --- a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet @@ -187,8 +187,6 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; withAlertmanagers:: { local tr = self, config+:: { - ruleConfigMapName: error 'must provide ruleConfigMapName', - ruleFileKey: error 'must provide ruleFileKey', alertmanagersURL: error 'must provide alertmanagersURL', }, @@ -201,8 +199,32 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; args+: [ '--alertmanagers.url=' + alertmanagerURL, for alertmanagerURL in tr.config.alertmanagersURL - ] + [ - '--rule-file=/etc/thanos/rules/' + tr.config.ruleFileKey, + ], + } else c + for c in super.containers + ], + }, + }, + }, + }, + }, + + withRules:: { + local tr = self, + config+:: { + ruleConfigMapName: error 'must provide ruleConfigMapName', + ruleFilesKey: error 'must provide ruleFilesKey', + }, + + statefulSet+: { + spec+: { + template+: { + spec+: { + containers: [ + if c.name == 'thanos-rule' then c { + args+: [ + '--rule-file=/etc/thanos/rules/' + ruleFileKey, + for ruleFileKey in tr.config.ruleFilesKey ], volumeMounts+: [ { name: 'rules-config', mountPath: '/etc/thanos/rules' }, From e7018916324709405076eb0403eb504c65523a95 Mon Sep 17 00:00:00 2001 From: clyang82 Date: Wed, 23 Sep 2020 16:52:15 +0800 Subject: [PATCH 6/6] Support multiple configmap Signed-off-by: clyang82 --- jsonnet/kube-thanos/kube-thanos-rule.libsonnet | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet index ab98519d..3892f4d5 100644 --- a/jsonnet/kube-thanos/kube-thanos-rule.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-rule.libsonnet @@ -212,8 +212,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; withRules:: { local tr = self, config+:: { - ruleConfigMapName: error 'must provide ruleConfigMapName', - ruleFilesKey: error 'must provide ruleFilesKey', + rulesConfig: error 'must provide rulesConfig', }, statefulSet+: { @@ -223,11 +222,12 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; containers: [ if c.name == 'thanos-rule' then c { args+: [ - '--rule-file=/etc/thanos/rules/' + ruleFileKey, - for ruleFileKey in tr.config.ruleFilesKey + '--rule-file=/etc/thanos/rules/' + ruleConfig.name + '/' + ruleConfig.key, + for ruleConfig in tr.config.rulesConfig ], volumeMounts+: [ - { name: 'rules-config', mountPath: '/etc/thanos/rules' }, + { name: ruleConfig.name, mountPath: '/etc/thanos/rules/' + ruleConfig.name }, + for ruleConfig in tr.config.rulesConfig ], } else c for c in super.containers @@ -235,8 +235,9 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; local volume = k.apps.v1.statefulSet.mixin.spec.template.spec.volumesType, volumes+: [ - volume.withName('rules-config') + - volume.mixin.configMap.withName(tr.config.ruleConfigMapName), + volume.withName(ruleConfig.name) + + volume.mixin.configMap.withName(ruleConfig.name), + for ruleConfig in tr.config.rulesConfig ], }, },