Skip to content

Commit 46e58df

Browse files
authored
Merge pull request kubernetes#79578 from cezarsa/stable-node-images
kubelet: ensure stable order for images in node status
2 parents 3e962cb + d96c2f6 commit 46e58df

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/kubelet/util/sliceutils/sliceutils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (s PodsByCreationTime) Less(i, j int) bool {
5353
type ByImageSize []kubecontainer.Image
5454

5555
func (a ByImageSize) Less(i, j int) bool {
56+
if a[i].Size == a[j].Size {
57+
return a[i].ID > a[j].ID
58+
}
5659
return a[i].Size > a[j].Size
5760
}
5861
func (a ByImageSize) Len() int { return len(a) }

pkg/kubelet/util/sliceutils/sliceutils_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ func buildByImageSize() ByImageSize {
160160
RepoDigests: []string{"foo-rd31", "foo-rd32"},
161161
Size: 3,
162162
},
163+
{
164+
ID: "4",
165+
RepoTags: []string{"foo-tag41", "foo-tag42"},
166+
RepoDigests: []string{"foo-rd41", "foo-rd42"},
167+
Size: 3,
168+
},
163169
}
164170
}
165171

@@ -169,7 +175,7 @@ func TestByImageSizeLen(t *testing.T) {
169175
el int
170176
}{
171177
{[]kubecontainer.Image{}, 0},
172-
{buildByImageSize(), 3},
178+
{buildByImageSize(), 4},
173179
{nil, 0},
174180
}
175181

@@ -211,6 +217,7 @@ func TestByImageSizeLess(t *testing.T) {
211217
// descending order
212218
{buildByImageSize(), 0, 2, false},
213219
{buildByImageSize(), 1, 0, true},
220+
{buildByImageSize(), 3, 2, true},
214221
}
215222

216223
for _, fooTest := range fooTests {

0 commit comments

Comments
 (0)