Skip to content

Commit

Permalink
Merge pull request #2904 from parth-gr/fix-external-reconcile
Browse files Browse the repository at this point in the history
external: Defer secret hash update until all resources are successfully created
  • Loading branch information
openshift-merge-bot[bot] authored Nov 22, 2024
2 parents 0d54af2 + 45e4b7b commit 3ef212d
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 3ef212d

Please sign in to comment.