From 1b5e3755b9b08a469566fed83ab6382c5dafc7f7 Mon Sep 17 00:00:00 2001 From: Ryotaro Banno Date: Wed, 4 Dec 2024 02:49:09 +0000 Subject: [PATCH] check restoring PV finalizer before checking cluster ID in PersisntetVolumeReconciler `getCephClusterIDFromSCName` works correctly only for storage class names provisioned by Rook/Ceph. However, the PVs requested to PersistentVolumeReconciler aren't necessarily provisioned by Rook/Ceph. This commit resolves the problem above by checking that the PV has the correct finalizer before checking calling `getCephClusterIDFromSCName`. Signed-off-by: Ryotaro Banno --- internal/controller/persistentvolume_controller.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/controller/persistentvolume_controller.go b/internal/controller/persistentvolume_controller.go index 6c9d28a..ec0043d 100644 --- a/internal/controller/persistentvolume_controller.go +++ b/internal/controller/persistentvolume_controller.go @@ -64,6 +64,11 @@ func (r *PersistentVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, fmt.Errorf("failed to get PersistentVolume: %w", err) } + // Make sure the PV has the finalizer. + if !controllerutil.ContainsFinalizer(&pv, RestoringPVFinalizerName) { + return ctrl.Result{}, nil + } + // Check if the PV is managed by the target Ceph cluster. clusterID, err := getCephClusterIDFromSCName(ctx, r.client, pv.Spec.StorageClassName) if err != nil { @@ -77,11 +82,6 @@ func (r *PersistentVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, nil } - // Make sure the PV has the finalizer. - if !controllerutil.ContainsFinalizer(&pv, RestoringPVFinalizerName) { - return ctrl.Result{}, nil - } - // Make sure the PV has a deletionTimestamp. if pv.GetDeletionTimestamp().IsZero() { return ctrl.Result{}, nil