From 3927ef008fef75ca9a300c7589d623ecc9fb090e Mon Sep 17 00:00:00 2001 From: Blaine Gardner Date: Fri, 7 Aug 2026 12:42:40 -0600 Subject: [PATCH] core: add workaround for ctx race after admin cephx rotation Add a workaround for https://github.com/rook/rook/issues/18112. This is not a proper fix but is a quick fix that will prevent the race involving operator reload and `ClusterController`'s near-global context.Context from allowing multiple simultaneous CephCluster reconciles of the same cluster object. There may be other ways in which a CephCluster reconcile could enter this race, but this workaround should reliably resolve the entry after admin cephx key rotation. Possible entry after this workaround is in place could involve systems where the rook-ceph-operator pod is running on a node with high CPU load which might prevent an ongoing CephCluster reconcile from getting CPU cycles needed to exit following context cancellation before the sleep added in this workaround. Signed-off-by: Blaine Gardner (cherry picked from commit 05ac850f7b6a049af4cd670bbed1e6f9f8db3315) --- pkg/operator/ceph/cluster/controller.go | 9 +++++++++ pkg/operator/ceph/operator.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/pkg/operator/ceph/cluster/controller.go b/pkg/operator/ceph/cluster/controller.go index 233782308..e3e92d3cb 100644 --- a/pkg/operator/ceph/cluster/controller.go +++ b/pkg/operator/ceph/cluster/controller.go @@ -320,6 +320,15 @@ func (r *ReconcileCephCluster) Reconcile(context context.Context, request reconc } func (r *ReconcileCephCluster) reconcile(request reconcile.Request) (reconcile.Result, cephv1.CephCluster, error) { + if err := r.opManagerContext.Err(); err != nil { + log.NamespacedInfo(request.Namespace, logger, "context cancelled before entering reconcile, exiting reconcile") + emptyCephCluster := cephv1.CephCluster{ObjectMeta: metav1.ObjectMeta{ + Namespace: request.Namespace, + Name: request.Name, + }} + return reconcile.Result{}, emptyCephCluster, nil + } + // Pass the client context to the ClusterController r.clusterController.client = r.client diff --git a/pkg/operator/ceph/operator.go b/pkg/operator/ceph/operator.go index 2674c41ab..45a88ce0c 100644 --- a/pkg/operator/ceph/operator.go +++ b/pkg/operator/ceph/operator.go @@ -113,6 +113,9 @@ func (o *Operator) Run() error { // Stop the operator CRD manager opManagerStop() + // Short sleep to quickly work around https://github.com/rook/rook/issues/18112 + time.Sleep(5 * time.Second) + // Run the operator CRD manager again o.runCRDManager() @@ -140,6 +143,7 @@ func (o *Operator) runCRDManager() { // Pass the parent context to the cluster controller so that the monitoring go routines can // consume it to terminate gracefully + logger.Info("swapping clusterController context") // debug https://github.com/rook/rook/issues/18112 o.clusterController.OpManagerCtx = opManagerContext // Run the operator CRD manager