Skip to content

Commit 5800df6

Browse files
committed
Fix requeue logic in the common controller
1 parent 4800ca7 commit 5800df6

File tree

10 files changed

+164
-660
lines changed

10 files changed

+164
-660
lines changed

pkg/common-controller/framework_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ func (r *snapshotReactor) getChangeCount() int {
582582
// waitForIdle waits until all tests, controllers and other goroutines do their
583583
// job and no new actions are registered for 10 milliseconds.
584584
func (r *snapshotReactor) waitForIdle() {
585-
r.ctrl.runningOperations.WaitForCompletion()
586585
// Check every 10ms if the controller does something and stop if it's
587586
// idle.
588587
oldChanges := -1
@@ -609,9 +608,6 @@ func (r *snapshotReactor) waitTest(test controllerTest) error {
609608
Steps: 10,
610609
}
611610
err := wait.ExponentialBackoff(backoff, func() (done bool, err error) {
612-
// Finish all operations that are in progress
613-
r.ctrl.runningOperations.WaitForCompletion()
614-
615611
// Return 'true' if the reactor reached the expected state
616612
err1 := r.checkSnapshots(test.expectedSnapshots)
617613
err2 := r.checkContents(test.expectedContents)
@@ -757,8 +753,6 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
757753
ctrl.snapshotListerSynced = alwaysReady
758754
ctrl.classListerSynced = alwaysReady
759755
ctrl.pvcListerSynced = alwaysReady
760-
ctrl.createSnapshotContentInterval = time.Millisecond * 5
761-
ctrl.createSnapshotContentRetryCount = 3
762756

763757
return ctrl, nil
764758
}

pkg/common-controller/snapshot_controller.go

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,10 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
423423
}
424424

425425
// update snapshot status
426-
for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ {
427-
klog.V(5).Infof("syncUnreadySnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshot))
428-
_, err = ctrl.updateSnapshotStatus(snapshot, newContent)
429-
if err == nil {
430-
break
431-
}
432-
klog.V(4).Infof("failed to update snapshot %s status: %v", utils.SnapshotKey(snapshot), err)
433-
time.Sleep(ctrl.createSnapshotContentInterval)
434-
}
435-
436-
if err != nil {
426+
klog.V(5).Infof("syncUnreadySnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshot))
427+
if _, err = ctrl.updateSnapshotStatus(snapshot, newContent); err != nil {
437428
// update snapshot status failed
429+
klog.V(4).Infof("failed to update snapshot %s status: %v", utils.SnapshotKey(snapshot), err)
438430
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotStatusUpdateFailed", fmt.Sprintf("Snapshot status update failed, %v", err))
439431
return err
440432
}
@@ -474,17 +466,8 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
474466
}
475467

476468
// Update snapshot status with BoundVolumeSnapshotContentName
477-
for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ {
478-
klog.V(5).Infof("syncUnreadySnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshot))
479-
_, err = ctrl.updateSnapshotStatus(snapshot, content)
480-
if err == nil {
481-
break
482-
}
483-
klog.V(4).Infof("failed to update snapshot %s status: %v", utils.SnapshotKey(snapshot), err)
484-
time.Sleep(ctrl.createSnapshotContentInterval)
485-
}
486-
487-
if err != nil {
469+
klog.V(5).Infof("syncUnreadySnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshot))
470+
if _, err = ctrl.updateSnapshotStatus(snapshot, content); err != nil {
488471
// update snapshot status failed
489472
ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotStatusUpdateFailed", fmt.Sprintf("Snapshot status update failed, %v", err))
490473
return err
@@ -656,24 +639,18 @@ func (ctrl *csiSnapshotCommonController) createSnapshotContent(snapshot *crdv1.V
656639
}
657640

658641
var updateContent *crdv1.VolumeSnapshotContent
659-
klog.V(3).Infof("volume snapshot content %#v", snapshotContent)
660-
// Try to create the VolumeSnapshotContent object several times
661-
for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ {
662-
klog.V(5).Infof("createSnapshotContent [%s]: trying to save volume snapshot content %s", utils.SnapshotKey(snapshot), snapshotContent.Name)
663-
if updateContent, err = ctrl.clientset.SnapshotV1beta1().VolumeSnapshotContents().Create(context.TODO(), snapshotContent, metav1.CreateOptions{}); err == nil || apierrs.IsAlreadyExists(err) {
664-
// Save succeeded.
665-
if err != nil {
666-
klog.V(3).Infof("volume snapshot content %q for snapshot %q already exists, reusing", snapshotContent.Name, utils.SnapshotKey(snapshot))
667-
err = nil
668-
updateContent = snapshotContent
669-
} else {
670-
klog.V(3).Infof("volume snapshot content %q for snapshot %q saved, %v", snapshotContent.Name, utils.SnapshotKey(snapshot), snapshotContent)
671-
}
672-
break
642+
klog.V(5).Infof("volume snapshot content %#v", snapshotContent)
643+
// Try to create the VolumeSnapshotContent object
644+
klog.V(5).Infof("createSnapshotContent [%s]: trying to save volume snapshot content %s", utils.SnapshotKey(snapshot), snapshotContent.Name)
645+
if updateContent, err = ctrl.clientset.SnapshotV1beta1().VolumeSnapshotContents().Create(context.TODO(), snapshotContent, metav1.CreateOptions{}); err == nil || apierrs.IsAlreadyExists(err) {
646+
// Save succeeded.
647+
if err != nil {
648+
klog.V(3).Infof("volume snapshot content %q for snapshot %q already exists, reusing", snapshotContent.Name, utils.SnapshotKey(snapshot))
649+
err = nil
650+
updateContent = snapshotContent
651+
} else {
652+
klog.V(3).Infof("volume snapshot content %q for snapshot %q saved, %v", snapshotContent.Name, utils.SnapshotKey(snapshot), snapshotContent)
673653
}
674-
// Save failed, try again after a while.
675-
klog.V(3).Infof("failed to save volume snapshot content %q for snapshot %q: %v", snapshotContent.Name, utils.SnapshotKey(snapshot), err)
676-
time.Sleep(ctrl.createSnapshotContentInterval)
677654
}
678655

679656
if err != nil {
@@ -982,19 +959,14 @@ func (ctrl *csiSnapshotCommonController) bindandUpdateVolumeSnapshot(snapshotCon
982959
snapshotCopy := snapshotObj.DeepCopy()
983960
// update snapshot status
984961
var updateSnapshot *crdv1.VolumeSnapshot
985-
for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ {
986-
klog.V(5).Infof("bindandUpdateVolumeSnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshotCopy))
987-
updateSnapshot, err = ctrl.updateSnapshotStatus(snapshotCopy, snapshotContent)
988-
if err == nil {
989-
snapshotCopy = updateSnapshot
990-
break
991-
}
992-
klog.V(4).Infof("failed to update snapshot %s status: %v", utils.SnapshotKey(snapshot), err)
993-
time.Sleep(ctrl.createSnapshotContentInterval)
962+
klog.V(5).Infof("bindandUpdateVolumeSnapshot [%s]: trying to update snapshot status", utils.SnapshotKey(snapshotCopy))
963+
updateSnapshot, err = ctrl.updateSnapshotStatus(snapshotCopy, snapshotContent)
964+
if err == nil {
965+
snapshotCopy = updateSnapshot
994966
}
995-
996967
if err != nil {
997968
// update snapshot status failed
969+
klog.V(4).Infof("failed to update snapshot %s status: %v", utils.SnapshotKey(snapshot), err)
998970
ctrl.updateSnapshotErrorStatusWithEvent(snapshotCopy, v1.EventTypeWarning, "SnapshotStatusUpdateFailed", fmt.Sprintf("Snapshot status update failed, %v", err))
999971
return nil, err
1000972
}

0 commit comments

Comments
 (0)