From e1bcfd47da95c41dd1390b17bc75a5e3cc62565b Mon Sep 17 00:00:00 2001 From: qingwave Date: Tue, 4 Apr 2023 06:44:17 +0000 Subject: [PATCH] Sort unmounted volumes message in volume manager --- pkg/kubelet/volumemanager/volume_manager.go | 3 +++ .../volumemanager/volume_manager_test.go | 22 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/volumemanager/volume_manager.go b/pkg/kubelet/volumemanager/volume_manager.go index 7de1d03fbbe..a0db4f8dc16 100644 --- a/pkg/kubelet/volumemanager/volume_manager.go +++ b/pkg/kubelet/volumemanager/volume_manager.go @@ -493,6 +493,7 @@ func (vm *volumeManager) getUnattachedVolumes(uniquePodName types.UniquePodName) unattachedVolumes = append(unattachedVolumes, volumeToMount.OuterVolumeSpecName) } } + sort.Strings(unattachedVolumes) return unattachedVolumes } @@ -540,6 +541,8 @@ func filterUnmountedVolumes(mountedVolumes sets.String, expectedVolumes []string unmountedVolumes = append(unmountedVolumes, expectedVolume) } } + sort.Strings(unmountedVolumes) + return unmountedVolumes } diff --git a/pkg/kubelet/volumemanager/volume_manager_test.go b/pkg/kubelet/volumemanager/volume_manager_test.go index a721f9249e0..81f6ab2c8ab 100644 --- a/pkg/kubelet/volumemanager/volume_manager_test.go +++ b/pkg/kubelet/volumemanager/volume_manager_test.go @@ -165,10 +165,18 @@ func TestWaitForAttachAndMountError(t *testing.T) { Name: "vol2", MountPath: "/vol2", }, + { + Name: "vol02", + MountPath: "/vol02", + }, { Name: "vol3", MountPath: "/vol3", }, + { + Name: "vol03", + MountPath: "/vol03", + }, }, }, }, @@ -185,12 +193,24 @@ func TestWaitForAttachAndMountError(t *testing.T) { RBD: &v1.RBDVolumeSource{}, }, }, + { + Name: "vol02", + VolumeSource: v1.VolumeSource{ + RBD: &v1.RBDVolumeSource{}, + }, + }, { Name: "vol3", VolumeSource: v1.VolumeSource{ 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") } 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) } }