Skip to content

Commit

Permalink
Skip PV patch step in Restoe workflow for WaitForFirstConsumer Volume…
Browse files Browse the repository at this point in the history
…BindingMode Pending state PVCs (#7953)

add changelog file

change log level and add more detailed comments

make update

add return for sc get call if error

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
(cherry picked from commit 3bd8a7d)

update changelog

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
  • Loading branch information
shubham-pampattiwar committed Jul 12, 2024
1 parent 1c7412d commit 7cb5b96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/8006-shubham-pampattiwar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip PV patch step in Restoe workflow for WaitForFirstConsumer VolumeBindingMode Pending state PVCs
23 changes: 23 additions & 0 deletions pkg/controller/restore_finalizer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"sync"
"time"

storagev1api "k8s.io/api/storage/v1"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -304,6 +306,27 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result
return false, err
}

// We are handling a common but specific scenario where a PVC is in a pending state and uses a storage class with
// VolumeBindingMode set to WaitForFirstConsumer. In this case, the PV patch step is skipped to avoid
// failures due to the PVC not being bound, which could cause a timeout and result in a failed restore.
if pvc != nil && pvc.Status.Phase == v1.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)

Check warning on line 316 in pkg/controller/restore_finalizer_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/restore_finalizer_controller.go#L314-L316

Added lines #L314 - L316 were not covered by tests

if err != nil {
errs.Add(restoredNamespace, err)
return false, err

Check warning on line 320 in pkg/controller/restore_finalizer_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/restore_finalizer_controller.go#L318-L320

Added lines #L318 - L320 were not covered by tests
}
// 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

Check warning on line 326 in pkg/controller/restore_finalizer_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/restore_finalizer_controller.go#L324-L326

Added lines #L324 - L326 were not covered by tests
}
}

if pvc.Status.Phase != v1.ClaimBound || pvc.Spec.VolumeName == "" {
log.Debugf("PVC: %s not ready", pvc.Name)
return false, nil
Expand Down

0 comments on commit 7cb5b96

Please sign in to comment.