subvolumegroup: add retry when updating status

currently, in SVG crd while updating status we don't have retryOnConflicts
similar to other CRD, this commit add the retryOnConflicts.

Signed-off-by: subhamkrai <srai@redhat.com>
(cherry picked from commit e9d5efb3e1)
This commit is contained in:
subhamkrai authored and Mergify committed 2025-11-13 17:39:15 +00:00
1 parent ae21f07d88
commit 0c3efeb870
1 file changed
+27 -21
@@ -48,6 +48,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
cephcsi "github.com/ceph/ceph-csi/api/deploy/kubernetes"
)
@@ -423,30 +424,35 @@ func (r *ReconcileCephFilesystemSubVolumeGroup) deleteSubVolumeGroup(cephFilesys
// updateStatus updates an object with a given status
func (r *ReconcileCephFilesystemSubVolumeGroup) updateStatus(observedGeneration int64, name types.NamespacedName, status cephv1.ConditionType) {
cephFilesystemSubVolumeGroup := &cephv1.CephFilesystemSubVolumeGroup{}
if err := r.client.Get(r.opManagerContext, name, cephFilesystemSubVolumeGroup); err != nil {
if kerrors.IsNotFound(err) {
logger.Debugf("CephFilesystemSubVolumeGroup %q not found. Ignoring since object must be deleted.", name)
return
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
cephFilesystemSubVolumeGroup := &cephv1.CephFilesystemSubVolumeGroup{}
if err := r.client.Get(r.opManagerContext, name, cephFilesystemSubVolumeGroup); err != nil {
if kerrors.IsNotFound(err) {
logger.Debugf("CephFilesystemSubVolumeGroup %q not found. Ignoring since object must be deleted.", name)
return nil
}
return errors.Wrapf(err, "failed to retrieve ceph filesystem subvolume group %q to update status to %q", name, status)
}
if cephFilesystemSubVolumeGroup.Status == nil {
cephFilesystemSubVolumeGroup.Status = &cephv1.CephFilesystemSubVolumeGroupStatus{}
}
logger.Warningf("failed to retrieve ceph filesystem subvolume group %q to update status to %q. %v", name, status, err)
return
}
if cephFilesystemSubVolumeGroup.Status == nil {
cephFilesystemSubVolumeGroup.Status = &cephv1.CephFilesystemSubVolumeGroupStatus{}
}
cephFilesystemSubVolumeGroup.Status.Phase = status
cephFilesystemSubVolumeGroup.Status.Info = map[string]string{
"clusterID": buildClusterID(cephFilesystemSubVolumeGroup),
"pinning": formatPinning(cephFilesystemSubVolumeGroup.Spec.Pinning),
}
cephFilesystemSubVolumeGroup.Status.Phase = status
cephFilesystemSubVolumeGroup.Status.Info = map[string]string{
"clusterID": buildClusterID(cephFilesystemSubVolumeGroup),
"pinning": formatPinning(cephFilesystemSubVolumeGroup.Spec.Pinning),
}
if observedGeneration != k8sutil.ObservedGenerationNotAvailable {
cephFilesystemSubVolumeGroup.Status.ObservedGeneration = observedGeneration
}
if err := reporting.UpdateStatus(r.client, cephFilesystemSubVolumeGroup); err != nil {
logger.Errorf("failed to set ceph filesystem subvolume group %q status to %q. %v", name, status, err)
if observedGeneration != k8sutil.ObservedGenerationNotAvailable {
cephFilesystemSubVolumeGroup.Status.ObservedGeneration = observedGeneration
}
if err := reporting.UpdateStatus(r.client, cephFilesystemSubVolumeGroup); err != nil {
return errors.Wrapf(err, "failed to set ceph filesystem subvolume group %q status to %q", name, status)
}
return nil
})
if err != nil {
logger.Errorf("failed to update ceph filesystem subvolume group %q status to %q after retries. %v", name, status, err)
return
}
logger.Debugf("ceph filesystem subvolume group %q status updated to %q", name, status)