Merge pull request #79578 from cezarsa/stable-node-images

kubelet: ensure stable order for images in node status
This commit is contained in:
Kubernetes Prow Robot 2019-08-10 08:59:12 -07:00 committed by GitHub
commit 46e58df837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -53,6 +53,9 @@ func (s PodsByCreationTime) Less(i, j int) bool {
type ByImageSize []kubecontainer.Image
func (a ByImageSize) Less(i, j int) bool {
if a[i].Size == a[j].Size {
return a[i].ID > a[j].ID
}
return a[i].Size > a[j].Size
}
func (a ByImageSize) Len() int { return len(a) }

View File

@ -160,6 +160,12 @@ func buildByImageSize() ByImageSize {
RepoDigests: []string{"foo-rd31", "foo-rd32"},
Size: 3,
},
{
ID: "4",
RepoTags: []string{"foo-tag41", "foo-tag42"},
RepoDigests: []string{"foo-rd41", "foo-rd42"},
Size: 3,
},
}
}
@ -169,7 +175,7 @@ func TestByImageSizeLen(t *testing.T) {
el int
}{
{[]kubecontainer.Image{}, 0},
{buildByImageSize(), 3},
{buildByImageSize(), 4},
{nil, 0},
}
@ -211,6 +217,7 @@ func TestByImageSizeLess(t *testing.T) {
// descending order
{buildByImageSize(), 0, 2, false},
{buildByImageSize(), 1, 0, true},
{buildByImageSize(), 3, 2, true},
}
for _, fooTest := range fooTests {