Skip to content

Commit

Permalink
Defer secret hash update until all resources are successfully created
Browse files Browse the repository at this point in the history
This update ensures that the secret hash in the storage
cluster status is updated only after all resources are created
successfully.
Previously, the status was updated prematurely, preventing the
reconcile loop from re-running whether there was a failure or success.
This change enables the reconcile process to continue retrying
until all resources are successfully created.

Signed-off-by: parth-gr <paarora@redhat.com>
  • Loading branch information
parth-gr committed Nov 22, 2024
1 parent 2e7cf01 commit 45e4b7b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions controllers/storagecluster/external_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,14 @@ func findNamedResourceFromArray(extArr []ExternalResource, name string) (Externa
return ExternalResource{}, fmt.Errorf("Unable to retrieve %q external resource", name)
}

func (r *StorageClusterReconciler) externalSecretDataChecksum(instance *ocsv1.StorageCluster) (string, error) {
func (r *StorageClusterReconciler) getExternalSecretDataChecksum(instance *ocsv1.StorageCluster) (string, error) {
found, err := r.retrieveSecret(externalClusterDetailsSecret, instance)
if err != nil {
return "", err
}
return sha512sum(found.Data[externalClusterDetailsKey])
}

func (r *StorageClusterReconciler) sameExternalSecretData(instance *ocsv1.StorageCluster) bool {
extSecretChecksum, err := r.externalSecretDataChecksum(instance)
if err != nil {
return false
}
// if the 'ExternalSecretHash' and fetched hash are same, then return true
if instance.Status.ExternalSecretHash == extSecretChecksum {
return true
}
// at this point the checksums are different, so update it
instance.Status.ExternalSecretHash = extSecretChecksum
return false
}

// retrieveSecret function retrieves the secret object with the specified name
func (r *StorageClusterReconciler) retrieveSecret(secretName string, instance *ocsv1.StorageCluster) (*corev1.Secret, error) {
found := &corev1.Secret{
Expand Down Expand Up @@ -263,7 +249,14 @@ func (obj *ocsExternalResources) ensureCreated(r *StorageClusterReconciler, inst
}
externalOCSResources[instance.UID] = data

if r.sameExternalSecretData(instance) {
extSecretChecksum, err := r.getExternalSecretDataChecksum(instance)
if err != nil {
r.Log.Error(err, "Failed to get checksum of external secret data.")
return reconcile.Result{}, err
}

// if the 'ExternalSecretHash' and fetched hash are same, then return
if instance.Status.ExternalSecretHash == extSecretChecksum {
return reconcile.Result{}, nil
}

Expand All @@ -272,6 +265,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
}

// external resources are successfully created, update the checksums in the status
instance.Status.ExternalSecretHash = extSecretChecksum
return reconcile.Result{}, nil
}

Expand Down

0 comments on commit 45e4b7b

Please sign in to comment.