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 }