Sort unmounted volumes message in volume manager

This commit is contained in:
qingwave 2023-04-04 06:44:17 +00:00
parent d89d5ab268
commit e1bcfd47da
2 changed files with 24 additions and 1 deletions

View File

@ -493,6 +493,7 @@ func (vm *volumeManager) getUnattachedVolumes(uniquePodName types.UniquePodName)
unattachedVolumes = append(unattachedVolumes, volumeToMount.OuterVolumeSpecName) unattachedVolumes = append(unattachedVolumes, volumeToMount.OuterVolumeSpecName)
} }
} }
sort.Strings(unattachedVolumes)
return unattachedVolumes return unattachedVolumes
} }
@ -540,6 +541,8 @@ func filterUnmountedVolumes(mountedVolumes sets.String, expectedVolumes []string
unmountedVolumes = append(unmountedVolumes, expectedVolume) unmountedVolumes = append(unmountedVolumes, expectedVolume)
} }
} }
sort.Strings(unmountedVolumes)
return unmountedVolumes return unmountedVolumes
} }

View File

@ -165,10 +165,18 @@ func TestWaitForAttachAndMountError(t *testing.T) {
Name: "vol2", Name: "vol2",
MountPath: "/vol2", MountPath: "/vol2",
}, },
{
Name: "vol02",
MountPath: "/vol02",
},
{ {
Name: "vol3", Name: "vol3",
MountPath: "/vol3", MountPath: "/vol3",
}, },
{
Name: "vol03",
MountPath: "/vol03",
},
}, },
}, },
}, },
@ -185,12 +193,24 @@ func TestWaitForAttachAndMountError(t *testing.T) {
RBD: &v1.RBDVolumeSource{}, RBD: &v1.RBDVolumeSource{},
}, },
}, },
{
Name: "vol02",
VolumeSource: v1.VolumeSource{
RBD: &v1.RBDVolumeSource{},
},
},
{ {
Name: "vol3", Name: "vol3",
VolumeSource: v1.VolumeSource{ VolumeSource: v1.VolumeSource{
AzureDisk: &v1.AzureDiskVolumeSource{}, AzureDisk: &v1.AzureDiskVolumeSource{},
}, },
}, },
{
Name: "vol03",
VolumeSource: v1.VolumeSource{
AzureDisk: &v1.AzureDiskVolumeSource{},
},
},
}, },
}, },
} }
@ -209,7 +229,7 @@ func TestWaitForAttachAndMountError(t *testing.T) {
t.Errorf("Expected error, got none") t.Errorf("Expected error, got none")
} }
if !strings.Contains(err.Error(), if !strings.Contains(err.Error(),
"unattached volumes=[vol2], failed to process volumes=[vol3]") { "unattached volumes=[vol02 vol2], failed to process volumes=[vol03 vol3]") {
t.Errorf("Unexpected error info: %v", err) t.Errorf("Unexpected error info: %v", err)
} }
} }