From 71e44c929f42fa0a62beab309f59281a9df17fc2 Mon Sep 17 00:00:00 2001 From: Gustavo Fernandes de Carvalho <17139678+gusfcarvalho@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:44:58 -0300 Subject: [PATCH] Gc/fix clusterexternalsecret metrics (#4170) * fix: not ready metrics for some edge case conditions on ces Signed-off-by: Gustavo Carvalho * fix: failure conditions with no metrics Signed-off-by: Gustavo Carvalho --------- Signed-off-by: Gustavo Carvalho Co-authored-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> --- .../clusterexternalsecret_controller.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/controllers/clusterexternalsecret/clusterexternalsecret_controller.go b/pkg/controllers/clusterexternalsecret/clusterexternalsecret_controller.go index 961952f96..891ecba71 100644 --- a/pkg/controllers/clusterexternalsecret/clusterexternalsecret_controller.go +++ b/pkg/controllers/clusterexternalsecret/clusterexternalsecret_controller.go @@ -102,18 +102,33 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } if prevName := clusterExternalSecret.Status.ExternalSecretName; prevName != esName { // ExternalSecretName has changed, so remove the old ones + failedNamespaces := map[string]error{} for _, ns := range clusterExternalSecret.Status.ProvisionedNamespaces { if err := r.deleteExternalSecret(ctx, prevName, clusterExternalSecret.Name, ns); err != nil { log.Error(err, "could not delete ExternalSecret") - return ctrl.Result{}, err + failedNamespaces[ns] = err } } + if len(failedNamespaces) > 0 { + condition := NewClusterExternalSecretCondition(failedNamespaces) + SetClusterExternalSecretCondition(&clusterExternalSecret, *condition) + clusterExternalSecret.Status.FailedNamespaces = toNamespaceFailures(failedNamespaces) + return ctrl.Result{}, err + } } clusterExternalSecret.Status.ExternalSecretName = esName namespaces, err := r.getTargetNamespaces(ctx, &clusterExternalSecret) if err != nil { log.Error(err, "failed to get target Namespaces") + failedNamespaces := map[string]error{ + "unknown": err, + } + condition := NewClusterExternalSecretCondition(failedNamespaces) + SetClusterExternalSecretCondition(&clusterExternalSecret, *condition) + + clusterExternalSecret.Status.FailedNamespaces = toNamespaceFailures(failedNamespaces) + return ctrl.Result{}, err }