Skip to content

Commit

Permalink
external: return success only after all resources created
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
parth-gr committed Nov 21, 2024
1 parent 2e7cf01 commit 5504d93
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions controllers/storagecluster/external_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 5504d93

Please sign in to comment.