Browse Source

Gc/fix clusterexternalsecret metrics (#4170)

* fix: not ready metrics for some edge case conditions on ces

Signed-off-by: Gustavo Carvalho <gusfcarvalho@gmail.com>

* fix: failure conditions with no metrics

Signed-off-by: Gustavo Carvalho <gusfcarvalho@gmail.com>

---------

Signed-off-by: Gustavo Carvalho <gusfcarvalho@gmail.com>
Co-authored-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
Gustavo Fernandes de Carvalho 1 year ago
parent
commit
71e44c929f

+ 16 - 1
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
 	}