From 5504d93eaab945066cd16066a160119aff6afe3e Mon Sep 17 00:00:00 2001 From: parth-gr Date: Thu, 21 Nov 2024 22:39:13 +0530 Subject: [PATCH] external: return success only after all resources created currently the reconcile stops before the external resources are created if any failure occurs, Fix the reconcile to return success only when all the resources are created successfully Signed-off-by: parth-gr --- .../storagecluster/external_resources.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/controllers/storagecluster/external_resources.go b/controllers/storagecluster/external_resources.go index cf3330d17a..0444fda1f8 100644 --- a/controllers/storagecluster/external_resources.go +++ b/controllers/storagecluster/external_resources.go @@ -124,18 +124,17 @@ func (r *StorageClusterReconciler) externalSecretDataChecksum(instance *ocsv1.St return sha512sum(found.Data[externalClusterDetailsKey]) } -func (r *StorageClusterReconciler) sameExternalSecretData(instance *ocsv1.StorageCluster) bool { +func (r *StorageClusterReconciler) sameExternalSecretData(instance *ocsv1.StorageCluster) (string, bool) { extSecretChecksum, err := r.externalSecretDataChecksum(instance) if err != nil { - return false + return "", false } // if the 'ExternalSecretHash' and fetched hash are same, then return true if instance.Status.ExternalSecretHash == extSecretChecksum { - return true + return extSecretChecksum, true } - // at this point the checksums are different, so update it - instance.Status.ExternalSecretHash = extSecretChecksum - return false + + return extSecretChecksum, false } // retrieveSecret function retrieves the secret object with the specified name @@ -263,7 +262,8 @@ func (obj *ocsExternalResources) ensureCreated(r *StorageClusterReconciler, inst } externalOCSResources[instance.UID] = data - if r.sameExternalSecretData(instance) { + extSecretChecksum, sameSecret := r.sameExternalSecretData(instance) + if sameSecret { return reconcile.Result{}, nil } @@ -272,6 +272,9 @@ func (obj *ocsExternalResources) ensureCreated(r *StorageClusterReconciler, inst r.Log.Error(err, "Could not create ExternalStorageClusterResource.", "StorageCluster", klog.KRef(instance.Namespace, instance.Name)) return reconcile.Result{}, err } + + // at this point the checksums are different, so update it + instance.Status.ExternalSecretHash = extSecretChecksum return reconcile.Result{}, nil }