mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 20:00:07 +00:00
Merge pull request #136278 from AutuSnow/fix/kubelet/WaitForAllPodsUnmount
fix(kubelet):resolve loop variable capture bug in WaitForAllPodsUnmount
This commit is contained in:
@@ -516,6 +516,7 @@ func (vm *volumeManager) WaitForAllPodsUnmount(ctx context.Context, pods []*v1.P
|
||||
|
||||
funcs := make([]func() error, 0, len(pods))
|
||||
for _, pod := range pods {
|
||||
pod := pod
|
||||
funcs = append(funcs, func() error {
|
||||
return vm.WaitForUnmount(ctx, pod)
|
||||
})
|
||||
|
||||
@@ -743,6 +743,14 @@ func TestWaitForAllPodsUnmount(t *testing.T) {
|
||||
require.ErrorAs(t, err, &aggErr, "Expected error to be an Aggregate error")
|
||||
errs := aggErr.Errors()
|
||||
require.Len(t, errs, test.numPods, "Expected %d errors but got %d", test.numPods, len(errs))
|
||||
|
||||
// Verify that each pod's volume name appears in the error messages,
|
||||
// which proves different pods are being processed
|
||||
errString := err.Error()
|
||||
for i := 0; i < test.numPods; i++ {
|
||||
volumeName := fmt.Sprintf("fake/fake-device-%d", i)
|
||||
require.Contains(t, errString, volumeName, "Expected error to contain volume name %s for pod-%d", volumeName, i)
|
||||
}
|
||||
} else {
|
||||
require.NoError(t, err, "Expected no error")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user