From 1122d940a21fbdfe6d3b23b2a9c5ad1ff96b5cc2 Mon Sep 17 00:00:00 2001 From: Lorenzo Felletti Date: Fri, 8 Nov 2024 15:47:51 +0000 Subject: [PATCH 1/2] feat: add cluster to alerts description (when possible) --- alerts/kube_apiserver.libsonnet | 10 ++++++++-- lib/utils.libsonnet | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/alerts/kube_apiserver.libsonnet b/alerts/kube_apiserver.libsonnet index 7f4ced3dc..11c09b9ac 100644 --- a/alerts/kube_apiserver.libsonnet +++ b/alerts/kube_apiserver.libsonnet @@ -59,7 +59,10 @@ local utils = import '../lib/utils.libsonnet'; severity: 'warning', }, annotations: { - description: 'A client certificate used to authenticate to kubernetes apiserver is expiring in less than %s.' % (utils.humanizeSeconds($._config.certExpirationWarningSeconds)), + description: 'A client certificate used to authenticate to kubernetes apiserver is expiring in less than %s%s.' % [ + (utils.humanizeSeconds($._config.certExpirationWarningSeconds)), + utils.ifClusterLabelSet($._config, ' on cluster {{ $labels.%(clusterLabel)s }}' % $._config), + ], summary: 'Client certificate is about to expire.', }, }, @@ -75,7 +78,10 @@ local utils = import '../lib/utils.libsonnet'; severity: 'critical', }, annotations: { - description: 'A client certificate used to authenticate to kubernetes apiserver is expiring in less than %s.' % (utils.humanizeSeconds($._config.certExpirationCriticalSeconds)), + description: 'A client certificate used to authenticate to kubernetes apiserver is expiring in less than %s%s.' % [ + (utils.humanizeSeconds($._config.certExpirationCriticalSeconds)), + utils.ifClusterLabelSet($._config, ' on cluster {{ $labels.%(clusterLabel)s }}' % $._config), + ], summary: 'Client certificate is about to expire.', }, }, diff --git a/lib/utils.libsonnet b/lib/utils.libsonnet index 512d6e68f..e7b3f6d20 100644 --- a/lib/utils.libsonnet +++ b/lib/utils.libsonnet @@ -56,4 +56,8 @@ metric: labels.metric, }, }, + + // if clusterLabel is set, return the string, otherwise return an empty string + ifClusterLabelSet(config, string):: + if std.length(config.clusterLabel) > 0 then string else '', } From d8a8fc2e178302ba8b833217078d668a26f72319 Mon Sep 17 00:00:00 2001 From: Lorenzo Felletti Date: Tue, 19 Nov 2024 23:15:56 +0000 Subject: [PATCH 2/2] feat: use showMultiCluster instead of cluster label --- alerts/kube_apiserver.libsonnet | 4 ++-- lib/utils.libsonnet | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/alerts/kube_apiserver.libsonnet b/alerts/kube_apiserver.libsonnet index 11c09b9ac..558c2acd2 100644 --- a/alerts/kube_apiserver.libsonnet +++ b/alerts/kube_apiserver.libsonnet @@ -61,7 +61,7 @@ local utils = import '../lib/utils.libsonnet'; annotations: { description: 'A client certificate used to authenticate to kubernetes apiserver is expiring in less than %s%s.' % [ (utils.humanizeSeconds($._config.certExpirationWarningSeconds)), - utils.ifClusterLabelSet($._config, ' on cluster {{ $labels.%(clusterLabel)s }}' % $._config), + utils.ifShowMultiCluster($._config, ' on cluster {{ $labels.%(clusterLabel)s }}' % $._config), ], summary: 'Client certificate is about to expire.', }, @@ -80,7 +80,7 @@ local utils = import '../lib/utils.libsonnet'; annotations: { description: 'A client certificate used to authenticate to kubernetes apiserver is expiring in less than %s%s.' % [ (utils.humanizeSeconds($._config.certExpirationCriticalSeconds)), - utils.ifClusterLabelSet($._config, ' on cluster {{ $labels.%(clusterLabel)s }}' % $._config), + utils.ifShowMultiCluster($._config, ' on cluster {{ $labels.%(clusterLabel)s }}' % $._config), ], summary: 'Client certificate is about to expire.', }, diff --git a/lib/utils.libsonnet b/lib/utils.libsonnet index e7b3f6d20..934c11875 100644 --- a/lib/utils.libsonnet +++ b/lib/utils.libsonnet @@ -57,7 +57,7 @@ }, }, - // if clusterLabel is set, return the string, otherwise return an empty string - ifClusterLabelSet(config, string):: - if std.length(config.clusterLabel) > 0 then string else '', + // if showMultiCluster is true in config, return the string, otherwise return an empty string + ifShowMultiCluster(config, string):: + if config.showMultiCluster then string else '', }