From 6dd6f487caea173014dc03b3a2bf52459d86e585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lia=20Barroso?= Date: Thu, 7 Nov 2024 23:34:08 +0000 Subject: [PATCH] [feat] - am secret --- internal/analyzers/alertmanager.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/analyzers/alertmanager.go b/internal/analyzers/alertmanager.go index 4addbdc..24ba482 100644 --- a/internal/analyzers/alertmanager.go +++ b/internal/analyzers/alertmanager.go @@ -42,11 +42,6 @@ func RunAlertmanagerAnalyzer(ctx context.Context, clientSets *k8sutil.ClientSets if err := checkAlertmanagerSecret(ctx, clientSets, alertmanager.Spec.ConfigSecret, namespace); err != nil { return fmt.Errorf("error checking Alertmanager secret: %w", err) } - } else { - amConfigSecretName := fmt.Sprintf("alertmanager-%s-generated", alertmanager.Name) - if err := checkAlertmanagerSecret(ctx, clientSets, amConfigSecretName, namespace); err != nil { - return fmt.Errorf("error checking Alertmanager secret: %w", err) - } } slog.Info("Alertmanager is compliant, no issues found", "name", name, "namespace", namespace) @@ -54,9 +49,16 @@ func RunAlertmanagerAnalyzer(ctx context.Context, clientSets *k8sutil.ClientSets } func checkAlertmanagerSecret(ctx context.Context, clientSets *k8sutil.ClientSets, secretName, namespace string) error { - _, err := clientSets.KClient.CoreV1().Secrets(namespace).Get(ctx, secretName, metav1.GetOptions{}) + alertmanagerSecret, err := clientSets.KClient.CoreV1().Secrets(namespace).Get(ctx, secretName, metav1.GetOptions{}) if err != nil { return fmt.Errorf("failed to get alertmanager secret %s %v", secretName, err) } + if len(alertmanagerSecret.Data) == 0 { + return fmt.Errorf("alertmanager Secret %s is empty", secretName) + } + _, found := alertmanagerSecret.Data["alertmanager.yaml"] + if !found { + return fmt.Errorf("alertmanager.yaml key not found in Secret %s", secretName) + } return nil }