Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#8035 from shubham-pampattiwar/expose-…
Browse files Browse the repository at this point in the history
…pv-patch-max-timeout-rel-1.14

[release-1.14] Expose PVPatchMaximumDuration timeout for custom configuration
  • Loading branch information
Lyndon-Li authored Jul 23, 2024
2 parents 6ae34a1 + fea6316 commit ebafe12
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/8035-shubham-pampattiwar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make PVPatchMaximumDuration timeout configurable
1 change: 1 addition & 0 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
s.metrics,
s.crClient,
multiHookTracker,
s.config.resourceTimeout,
).SetupWithManager(s.mgr); err != nil {
s.logger.Fatal(err, "unable to create controller", "controller", controller.RestoreFinalizer)
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/controller/restore_finalizer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ import (
"github.com/vmware-tanzu/velero/pkg/util/results"
)

const (
PVPatchMaximumDuration = 10 * time.Minute
)

type restoreFinalizerReconciler struct {
client.Client
namespace string
Expand All @@ -59,6 +55,7 @@ type restoreFinalizerReconciler struct {
clock clock.WithTickerAndDelayedExecution
crClient client.Client
multiHookTracker *hook.MultiHookTracker
resourceTimeout time.Duration
}

func NewRestoreFinalizerReconciler(
Expand All @@ -70,6 +67,7 @@ func NewRestoreFinalizerReconciler(
metrics *metrics.ServerMetrics,
crClient client.Client,
multiHookTracker *hook.MultiHookTracker,
resourceTimeout time.Duration,
) *restoreFinalizerReconciler {
return &restoreFinalizerReconciler{
Client: client,
Expand All @@ -81,6 +79,7 @@ func NewRestoreFinalizerReconciler(
clock: &clock.RealClock{},
crClient: crClient,
multiHookTracker: multiHookTracker,
resourceTimeout: resourceTimeout,
}
}

Expand Down Expand Up @@ -163,6 +162,7 @@ func (r *restoreFinalizerReconciler) Reconcile(ctx context.Context, req ctrl.Req
volumeInfo: volumeInfo,
restoredPVCList: restoredPVCList,
multiHookTracker: r.multiHookTracker,
resourceTimeout: r.resourceTimeout,
}
warnings, errs := finalizerCtx.execute()

Expand Down Expand Up @@ -246,6 +246,7 @@ type finalizerContext struct {
volumeInfo []*volume.BackupVolumeInfo
restoredPVCList map[string]struct{}
multiHookTracker *hook.MultiHookTracker
resourceTimeout time.Duration
}

func (ctx *finalizerContext) execute() (results.Result, results.Result) { //nolint:unparam //temporarily ignore the lint report: result 0 is always nil (unparam)
Expand All @@ -268,6 +269,7 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result

var pvWaitGroup sync.WaitGroup
var resultLock sync.Mutex

maxConcurrency := 3
semaphore := make(chan struct{}, maxConcurrency)

Expand All @@ -294,7 +296,7 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result
log := ctx.logger.WithField("PVC", volInfo.PVCName).WithField("PVCNamespace", restoredNamespace)
log.Debug("patching dynamic PV is in progress")

err := wait.PollUntilContextTimeout(context.Background(), 10*time.Second, PVPatchMaximumDuration, true, func(context.Context) (bool, error) {
err := wait.PollUntilContextTimeout(context.Background(), 10*time.Second, ctx.resourceTimeout, true, func(context.Context) (bool, error) {
// wait for PVC to be bound
pvc := &v1.PersistentVolumeClaim{}
err := ctx.crClient.Get(context.Background(), client.ObjectKey{Name: volInfo.PVCName, Namespace: restoredNamespace}, pvc)
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/restore_finalizer_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func TestRestoreFinalizerReconcile(t *testing.T) {
metrics.NewServerMetrics(),
fakeClient,
hook.NewMultiHookTracker(),
10*time.Minute,
)
r.clock = testclocks.NewFakeClock(now)

Expand Down Expand Up @@ -200,6 +201,7 @@ func TestUpdateResult(t *testing.T) {
metrics.NewServerMetrics(),
fakeClient,
hook.NewMultiHookTracker(),
10*time.Minute,
)
restore := builder.ForRestore(velerov1api.DefaultNamespace, "restore-1").Result()
res := map[string]results.Result{"warnings": {}, "errors": {}}
Expand Down

0 comments on commit ebafe12

Please sign in to comment.