Skip to content

Commit

Permalink
[feat] - am secret
Browse files Browse the repository at this point in the history
  • Loading branch information
heliapb committed Nov 7, 2024
1 parent 8598256 commit 6dd6f48
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/analyzers/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@ 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)
return nil
}

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
}

0 comments on commit 6dd6f48

Please sign in to comment.