From c8ee7305d4eda9e3a23149eabc03f7d84e67310a Mon Sep 17 00:00:00 2001 From: subhamkrai Date: Mon, 3 Nov 2025 15:29:38 +0530 Subject: [PATCH] namespace: add retryOnConflict when updating status currently, in RNS crd while updating status we don't have retryOnConflicts, similar to other CRD due to this RNS status was not updated succesfully and to fix this we have restart the rook operator pod. Signed-off-by: subhamkrai --- pkg/daemon/ceph/client/mirror_health.go | 69 ++++++++++--------- .../ceph/pool/radosnamespace/controller.go | 36 ++++++---- 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/pkg/daemon/ceph/client/mirror_health.go b/pkg/daemon/ceph/client/mirror_health.go index 0b12ca7c9..b1c554648 100644 --- a/pkg/daemon/ceph/client/mirror_health.go +++ b/pkg/daemon/ceph/client/mirror_health.go @@ -25,6 +25,7 @@ import ( "github.com/rook/rook/pkg/operator/ceph/reporting" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/util/retry" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -154,42 +155,46 @@ func updatePoolStatusMirroring(c *mirrorChecker, mirrorStatus *cephv1.MirroringS } func updateRadosNamespaceStatusMirroring(c *mirrorChecker, mirrorStatus *cephv1.MirroringStatusSummarySpec, mirrorInfo *cephv1.MirroringInfo, snapSchedStatus []cephv1.SnapshotSchedulesSpec, details string) { - radosNamespace := &cephv1.CephBlockPoolRadosNamespace{} - if err := c.client.Get(c.clusterInfo.Context, c.namespacedName, radosNamespace); err != nil { - if kerrors.IsNotFound(err) { - logger.Debug("CephBlockPoolRadosNamespace %q resource not found for updating the mirroring status, ignoring.", c.namespacedName) - return + err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + radosNamespace := &cephv1.CephBlockPoolRadosNamespace{} + if err := c.client.Get(c.clusterInfo.Context, c.namespacedName, radosNamespace); err != nil { + if kerrors.IsNotFound(err) { + logger.Debug("CephBlockPoolRadosNamespace %q resource not found for updating the mirroring status, ignoring.", c.namespacedName) + return nil + } + return err } - logger.Warningf("failed to retrieve ceph block pool rados namespace %q to update mirroring status. %v", c.namespacedName.Name, err) - return - } - if radosNamespace.Status == nil { - radosNamespace.Status = &cephv1.CephBlockPoolRadosNamespaceStatus{} - } - - blockPool := &cephv1.CephBlockPool{} - namespaceName := types.NamespacedName{Name: radosNamespace.Spec.BlockPoolName, Namespace: radosNamespace.Namespace} - if err := c.client.Get(c.clusterInfo.Context, namespaceName, blockPool); err != nil { - if kerrors.IsNotFound(err) { - logger.Debug("CephBlockPool %q resource not found for updating the mirroring status, ignoring.", namespaceName) - return + if radosNamespace.Status == nil { + radosNamespace.Status = &cephv1.CephBlockPoolRadosNamespaceStatus{} } - logger.Warningf("failed to retrieve ceph block pool %q to update mirroring status. %v", namespaceName, err) - return - } - if blockPool.Spec.StatusCheck.Mirror.Disabled { - logger.Debugf("mirroring status check is disabled for %q", c.namespacedName.Name) - mirrorStatus = nil - mirrorInfo = nil - snapSchedStatus = nil - details = "" - } + blockPool := &cephv1.CephBlockPool{} + namespaceName := types.NamespacedName{Name: radosNamespace.Spec.BlockPoolName, Namespace: radosNamespace.Namespace} + if err := c.client.Get(c.clusterInfo.Context, namespaceName, blockPool); err != nil { + if kerrors.IsNotFound(err) { + logger.Debug("CephBlockPool %q resource not found for updating the mirroring status, ignoring.", namespaceName) + return nil + } + return err + } - // Update the CephBlockPoolRadosNamespace CR status field - radosNamespace.Status.MirroringStatus, radosNamespace.Status.MirroringInfo, radosNamespace.Status.SnapshotScheduleStatus = toCustomResourceStatus(radosNamespace.Status.MirroringStatus, mirrorStatus, radosNamespace.Status.MirroringInfo, mirrorInfo, radosNamespace.Status.SnapshotScheduleStatus, snapSchedStatus, details) - if err := reporting.UpdateStatus(c.client, radosNamespace); err != nil { - logger.Errorf("failed to set ceph block pool rados namespace %q mirroring status. %v", c.namespacedName.Name, err) + if blockPool.Spec.StatusCheck.Mirror.Disabled { + logger.Debugf("mirroring status check is disabled for %q", c.namespacedName.Name) + mirrorStatus = nil + mirrorInfo = nil + snapSchedStatus = nil + details = "" + } + + // Update the CephBlockPoolRadosNamespace CR status field + radosNamespace.Status.MirroringStatus, radosNamespace.Status.MirroringInfo, radosNamespace.Status.SnapshotScheduleStatus = toCustomResourceStatus(radosNamespace.Status.MirroringStatus, mirrorStatus, radosNamespace.Status.MirroringInfo, mirrorInfo, radosNamespace.Status.SnapshotScheduleStatus, snapSchedStatus, details) + if err := reporting.UpdateStatus(c.client, radosNamespace); err != nil { + return err + } + return nil + }) + if err != nil { + logger.Errorf("failed to set ceph block pool rados namespace %q mirroring status after retries. %v", c.namespacedName.Name, err) return } } diff --git a/pkg/operator/ceph/pool/radosnamespace/controller.go b/pkg/operator/ceph/pool/radosnamespace/controller.go index 4a2c93d94..641c4e98d 100644 --- a/pkg/operator/ceph/pool/radosnamespace/controller.go +++ b/pkg/operator/ceph/pool/radosnamespace/controller.go @@ -41,6 +41,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" + "k8s.io/client-go/util/retry" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/handler" @@ -466,23 +467,28 @@ func (r *ReconcileCephBlockPoolRadosNamespace) deleteRadosNamespace(radosNamespa // updateStatus updates an object with a given status func (r *ReconcileCephBlockPoolRadosNamespace) updateStatus(client client.Client, name types.NamespacedName, status cephv1.ConditionType) { - cephBlockPoolRadosNamespace := &cephv1.CephBlockPoolRadosNamespace{} - if err := client.Get(r.opManagerContext, name, cephBlockPoolRadosNamespace); err != nil { - if kerrors.IsNotFound(err) { - logger.Debugf("CephBlockPoolRadosNamespace resource %q not found. Ignoring since object must be deleted.", name) - return + err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + cephBlockPoolRadosNamespace := &cephv1.CephBlockPoolRadosNamespace{} + if err := client.Get(r.opManagerContext, name, cephBlockPoolRadosNamespace); err != nil { + if kerrors.IsNotFound(err) { + logger.Debugf("CephBlockPoolRadosNamespace resource %q not found. Ignoring since object must be deleted.", name) + return nil + } + return errors.Wrapf(err, "failed to retrieve ceph blockpool rados namespace %q to update status to %q", name, status) + } + if cephBlockPoolRadosNamespace.Status == nil { + cephBlockPoolRadosNamespace.Status = &cephv1.CephBlockPoolRadosNamespaceStatus{} } - logger.Warningf("failed to retrieve ceph blockpool rados namespace %q to update status to %q. %v", name, status, err) - return - } - if cephBlockPoolRadosNamespace.Status == nil { - cephBlockPoolRadosNamespace.Status = &cephv1.CephBlockPoolRadosNamespaceStatus{} - } - cephBlockPoolRadosNamespace.Status.Phase = status - cephBlockPoolRadosNamespace.Status.Info = map[string]string{"clusterID": buildClusterID(cephBlockPoolRadosNamespace)} - if err := reporting.UpdateStatus(client, cephBlockPoolRadosNamespace); err != nil { - logger.Errorf("failed to set ceph blockpool rados namespace %q status to %q. %v", name, status, err) + cephBlockPoolRadosNamespace.Status.Phase = status + cephBlockPoolRadosNamespace.Status.Info = map[string]string{"clusterID": buildClusterID(cephBlockPoolRadosNamespace)} + if err := reporting.UpdateStatus(client, cephBlockPoolRadosNamespace); err != nil { + return errors.Wrapf(err, "failed to set ceph blockpool rados namespace %q status to %q", name, status) + } + return nil + }) + if err != nil { + logger.Errorf("failed to update ceph blockpool rados namespace %q status to %q after retries. %v", name, status, err) return } logger.Debugf("ceph blockpool rados namespace %q status updated to %q", name, status)