mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #70027 from bart0sh/PR0031-kubeadm-sort-volumes
kubeadm: sort pod Volumes and VolumeMounts
This commit is contained in:
commit
46ec13cf7d
@ -23,6 +23,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
@ -148,6 +149,10 @@ func VolumeMapToSlice(volumes map[string]v1.Volume) []v1.Volume {
|
|||||||
v = append(v, vol)
|
v = append(v, vol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(v, func(i, j int) bool {
|
||||||
|
return strings.Compare(v[i].Name, v[j].Name) == -1
|
||||||
|
})
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +164,10 @@ func VolumeMountMapToSlice(volumeMounts map[string]v1.VolumeMount) []v1.VolumeMo
|
|||||||
v = append(v, volMount)
|
v = append(v, volMount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(v, func(i, j int) bool {
|
||||||
|
return strings.Compare(v[i].Name, v[j].Name) == -1
|
||||||
|
})
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,13 +482,19 @@ func TestVolumeMapToSlice(t *testing.T) {
|
|||||||
"foo": {
|
"foo": {
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
|
"bar": {
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
volumeSlice := VolumeMapToSlice(testVolumes)
|
volumeSlice := VolumeMapToSlice(testVolumes)
|
||||||
if len(volumeSlice) != 1 {
|
if len(volumeSlice) != 2 {
|
||||||
t.Errorf("Expected slice length of 1, got %d", len(volumeSlice))
|
t.Errorf("Expected slice length of 1, got %d", len(volumeSlice))
|
||||||
}
|
}
|
||||||
if volumeSlice[0].Name != "foo" {
|
if volumeSlice[0].Name != "bar" {
|
||||||
t.Errorf("Expected volume name \"foo\", got %s", volumeSlice[0].Name)
|
t.Errorf("Expected first volume name \"bar\", got %s", volumeSlice[0].Name)
|
||||||
|
}
|
||||||
|
if volumeSlice[1].Name != "foo" {
|
||||||
|
t.Errorf("Expected second volume name \"foo\", got %s", volumeSlice[1].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,13 +503,19 @@ func TestVolumeMountMapToSlice(t *testing.T) {
|
|||||||
"foo": {
|
"foo": {
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
|
"bar": {
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
volumeMountSlice := VolumeMountMapToSlice(testVolumeMounts)
|
volumeMountSlice := VolumeMountMapToSlice(testVolumeMounts)
|
||||||
if len(volumeMountSlice) != 1 {
|
if len(volumeMountSlice) != 2 {
|
||||||
t.Errorf("Expected slice length of 1, got %d", len(volumeMountSlice))
|
t.Errorf("Expected slice length of 1, got %d", len(volumeMountSlice))
|
||||||
}
|
}
|
||||||
if volumeMountSlice[0].Name != "foo" {
|
if volumeMountSlice[0].Name != "bar" {
|
||||||
t.Errorf("Expected volume mount name \"foo\", got %s", volumeMountSlice[0].Name)
|
t.Errorf("Expected first volume mount name \"bar\", got %s", volumeMountSlice[0].Name)
|
||||||
|
}
|
||||||
|
if volumeMountSlice[1].Name != "foo" {
|
||||||
|
t.Errorf("Expected second volume name \"foo\", got %s", volumeMountSlice[1].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user