From 293f6f6a63f29f0b34a5c5d9783b61494d9fb036 Mon Sep 17 00:00:00 2001 From: Daniel Jiang Date: Fri, 14 Aug 2026 19:26:15 +0800 Subject: [PATCH] Harden "patchDynamicPVWithVolumeInfo" (#10271) This commit hardens the func "patchDynamicPVWithVolumeInfo": 1. Add nil checks for storageClass and the attributes. 2. Remove the double reported errors. Signed-off-by: Daniel Jiang --- .../restore_finalizer_controller.go | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/controller/restore_finalizer_controller.go b/pkg/controller/restore_finalizer_controller.go index 4e02bb0ef..43e41d963 100644 --- a/pkg/controller/restore_finalizer_controller.go +++ b/pkg/controller/restore_finalizer_controller.go @@ -374,19 +374,20 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result // failures due to the PVC not being bound, which could cause a timeout and result in a failed restore. if pvc.Status.Phase == corev1api.ClaimPending { // check if storage class used has VolumeBindingMode as WaitForFirstConsumer - scName := *pvc.Spec.StorageClassName - sc := &storagev1api.StorageClass{} - err = ctx.crClient.Get(context.Background(), client.ObjectKey{Name: scName}, sc) + if pvc.Spec.StorageClassName != nil && *pvc.Spec.StorageClassName != "" { + scName := *pvc.Spec.StorageClassName + sc := &storagev1api.StorageClass{} + err = ctx.crClient.Get(context.Background(), client.ObjectKey{Name: scName}, sc) - if err != nil { - errs.Add(restoredNamespace, err) - return false, err - } - // skip PV patch step for this scenario - // because pvc would not be bound and the PV patch step would fail due to timeout thus failing the restore - if *sc.VolumeBindingMode == storagev1api.VolumeBindingWaitForFirstConsumer { - log.Warnf("skipping PV patch to restore custom reclaim policy, if any: StorageClass %s used by PVC %s has VolumeBindingMode set to WaitForFirstConsumer, and the PVC is also in a pending state", scName, pvc.Name) - return true, nil + if err != nil { + return false, err + } + // skip PV patch step for this scenario + // because pvc would not be bound and the PV patch step would fail due to timeout thus failing the restore + if sc.VolumeBindingMode != nil && *sc.VolumeBindingMode == storagev1api.VolumeBindingWaitForFirstConsumer { + log.Warnf("skipping PV patch to restore custom reclaim policy, if any: StorageClass %s used by PVC %s has VolumeBindingMode set to WaitForFirstConsumer, and the PVC is also in a pending state", scName, pvc.Name) + return true, nil + } } }