mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
Merge pull request #122790 from carlory/fix-121696
Fix flaky test: Test_Run_OneVolumeDetachFailNodeWithReadWriteOnce
This commit is contained in:
commit
611dbaa055
@ -630,9 +630,7 @@ func Test_Run_OneVolumeAttachAndDetachUncertainNodesWithReadWriteOnce(t *testing
|
|||||||
if podAddErr != nil {
|
if podAddErr != nil {
|
||||||
t.Fatalf("AddPod failed. Expected: <no error> Actual: <%v>", podAddErr)
|
t.Fatalf("AddPod failed. Expected: <no error> Actual: <%v>", podAddErr)
|
||||||
}
|
}
|
||||||
waitForVolumeAttachedToNode(t, generatedVolumeName, nodeName2, asw)
|
waitForVolumeAttachStateToNode(t, generatedVolumeName, nodeName2, cache.AttachStateAttached, asw)
|
||||||
verifyVolumeAttachedToNode(t, generatedVolumeName, nodeName2, cache.AttachStateAttached, asw)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Run_UpdateNodeStatusFailBeforeOneVolumeDetachNodeWithReadWriteOnce(t *testing.T) {
|
func Test_Run_UpdateNodeStatusFailBeforeOneVolumeDetachNodeWithReadWriteOnce(t *testing.T) {
|
||||||
@ -747,13 +745,7 @@ func Test_Run_OneVolumeDetachFailNodeWithReadWriteOnce(t *testing.T) {
|
|||||||
// Delete the pod, but detach will fail
|
// Delete the pod, but detach will fail
|
||||||
dsw.DeletePod(types.UniquePodName(podName1), generatedVolumeName, nodeName1)
|
dsw.DeletePod(types.UniquePodName(podName1), generatedVolumeName, nodeName1)
|
||||||
|
|
||||||
// The first detach will be triggered after at least 50ms (maxWaitForUnmountDuration in test).
|
waitForVolumeAttachStateToNode(t, generatedVolumeName, nodeName1, cache.AttachStateUncertain, asw)
|
||||||
// Right before detach operation is performed, the volume will be first removed from being reported
|
|
||||||
// as attached on node status (RemoveVolumeFromReportAsAttached). After detach operation which is expected to fail,
|
|
||||||
// controller then treats the attachment as Uncertain.
|
|
||||||
// Here it sleeps 100ms so that detach should be triggered already at this point.
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
verifyVolumeAttachedToNode(t, generatedVolumeName, nodeName1, cache.AttachStateUncertain, asw)
|
|
||||||
verifyVolumeReportedAsAttachedToNode(t, logger, generatedVolumeName, nodeName1, false, asw, volumeAttachedCheckTimeout)
|
verifyVolumeReportedAsAttachedToNode(t, logger, generatedVolumeName, nodeName1, false, asw, volumeAttachedCheckTimeout)
|
||||||
|
|
||||||
// Add a second pod which tries to attach the volume to the same node.
|
// Add a second pod which tries to attach the volume to the same node.
|
||||||
@ -843,9 +835,7 @@ func Test_Run_OneVolumeAttachAndDetachTimeoutNodesWithReadWriteOnce(t *testing.T
|
|||||||
if podAddErr != nil {
|
if podAddErr != nil {
|
||||||
t.Fatalf("AddPod failed. Expected: <no error> Actual: <%v>", podAddErr)
|
t.Fatalf("AddPod failed. Expected: <no error> Actual: <%v>", podAddErr)
|
||||||
}
|
}
|
||||||
waitForVolumeAttachedToNode(t, generatedVolumeName, nodeName2, asw)
|
waitForVolumeAttachStateToNode(t, generatedVolumeName, nodeName2, cache.AttachStateAttached, asw)
|
||||||
verifyVolumeAttachedToNode(t, generatedVolumeName, nodeName2, cache.AttachStateAttached, asw)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populates desiredStateOfWorld cache with one node/volume/pod tuple.
|
// Populates desiredStateOfWorld cache with one node/volume/pod tuple.
|
||||||
@ -1626,35 +1616,33 @@ func verifyNewAttacherCallCount(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForVolumeAttachedToNode(
|
func waitForVolumeAttachStateToNode(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
volumeName v1.UniqueVolumeName,
|
volumeName v1.UniqueVolumeName,
|
||||||
nodeName k8stypes.NodeName,
|
nodeName k8stypes.NodeName,
|
||||||
|
expectedAttachState cache.AttachState,
|
||||||
asw cache.ActualStateOfWorld) {
|
asw cache.ActualStateOfWorld) {
|
||||||
|
|
||||||
err := retryWithExponentialBackOff(
|
err := retryWithExponentialBackOff(
|
||||||
time.Duration(500*time.Millisecond),
|
time.Duration(500*time.Millisecond),
|
||||||
func() (bool, error) {
|
func() (bool, error) {
|
||||||
attachState := asw.GetAttachState(volumeName, nodeName)
|
attachState := asw.GetAttachState(volumeName, nodeName)
|
||||||
if attachState == cache.AttachStateAttached {
|
if attachState == expectedAttachState {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
t.Logf(
|
t.Logf("Warning: expected attach state: %v, actual attach state: %v. Will retry.",
|
||||||
"Warning: Volume <%v> is not attached to node <%v> yet. Will retry.",
|
expectedAttachState, attachState)
|
||||||
volumeName,
|
|
||||||
nodeName)
|
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
attachState := asw.GetAttachState(volumeName, nodeName)
|
attachState := asw.GetAttachState(volumeName, nodeName)
|
||||||
if err != nil && attachState != cache.AttachStateAttached {
|
if err != nil && attachState != expectedAttachState {
|
||||||
t.Fatalf(
|
t.Fatalf("Volume <%v> is not in expected attach state: %v, actual attach state: %v",
|
||||||
"Volume <%v> is not attached to node <%v>.",
|
volumeName, expectedAttachState, attachState)
|
||||||
volumeName,
|
|
||||||
nodeName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Logf("Volume <%v> is attached to node <%v>: %v", volumeName, nodeName, expectedAttachState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForVolumeAddedToNode(
|
func waitForVolumeAddedToNode(
|
||||||
|
Loading…
Reference in New Issue
Block a user