Skip to content

Commit dcac65a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#53831 from gnufied/fix-multiattach-error-flake
Automatic merge from submit-queue (batch tested with PRs 51840, 53542, 53857, 53831, 53702). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix possible flake in multiattach unit test It is possible that by the time we check for multiattach error on node, the reconciler loop may not have processed second volume and hence we are going to retry for multiattach error on node before giving up and marking the test as failed. Fixes openshift/origin#16836
2 parents e6e23ae + 68d417d commit dcac65a

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

pkg/controller/volume/attachdetach/reconciler/reconciler_test.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,9 @@ func Test_Run_OneVolumeAttachAndDetachMultipleNodesWithReadWriteOnce(t *testing.
456456
nodesForVolume := asw.GetNodesForVolume(generatedVolumeName)
457457

458458
// check if multiattach is marked
459-
// at least one volume should be marked with multiattach error
459+
// at least one volume+node should be marked with multiattach error
460460
nodeAttachedTo := nodesForVolume[0]
461-
for _, volumeToAttach := range dsw.GetVolumesToAttach() {
462-
if volumeToAttach.NodeName != nodeAttachedTo {
463-
if !volumeToAttach.MultiAttachErrorReported {
464-
t.Fatalf("Expected volume %q on node %q to have multiattach error", volumeToAttach.VolumeName, volumeToAttach.NodeName)
465-
}
466-
}
467-
}
461+
waitForMultiAttachErrorOnNode(t, nodeAttachedTo, dsw)
468462

469463
// Act
470464
podToDelete := ""
@@ -495,6 +489,28 @@ func Test_Run_OneVolumeAttachAndDetachMultipleNodesWithReadWriteOnce(t *testing.
495489
waitForTotalAttachCallCount(t, 2 /* expectedAttachCallCount */, fakePlugin)
496490
}
497491

492+
func waitForMultiAttachErrorOnNode(
493+
t *testing.T,
494+
attachedNode k8stypes.NodeName,
495+
dsow cache.DesiredStateOfWorld) {
496+
multAttachCheckFunc := func() (bool, error) {
497+
for _, volumeToAttach := range dsow.GetVolumesToAttach() {
498+
if volumeToAttach.NodeName != attachedNode {
499+
if volumeToAttach.MultiAttachErrorReported {
500+
return true, nil
501+
}
502+
}
503+
}
504+
t.Logf("Warning: MultiAttach error not yet set on Node. Will retry.")
505+
return false, nil
506+
}
507+
508+
err := retryWithExponentialBackOff(100*time.Millisecond, multAttachCheckFunc)
509+
if err != nil {
510+
t.Fatalf("Timed out waiting for MultiAttach Error to be set on non-attached node")
511+
}
512+
}
513+
498514
func waitForNewAttacherCallCount(
499515
t *testing.T,
500516
expectedCallCount int,

0 commit comments

Comments
 (0)