From 72a1a23a5318b856bf4b7052675196993569e663 Mon Sep 17 00:00:00 2001 From: Lorenzo Felletti <60483783+lorenzofelletti@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:43:33 +0000 Subject: [PATCH] feat: add cluster to alerts description (when possible) (#988) * feat: add cluster to alerts description (when possible) * feat: use showMultiCluster instead of cluster label --- 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..558c2acd2 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.ifShowMultiCluster($._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.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 512d6e68f..934c11875 100644 --- a/lib/utils.libsonnet +++ b/lib/utils.libsonnet @@ -56,4 +56,8 @@ metric: labels.metric, }, }, + + // if showMultiCluster is true in config, return the string, otherwise return an empty string + ifShowMultiCluster(config, string):: + if config.showMultiCluster then string else '', }