Unverified Commit c7b3e163 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #60448 from Random-Liu/image-cache-return-copy

Automatic merge from submit-queue (batch tested with PRs 59365, 60446, 60448, 55019, 60431). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Let image manager return a copy of image list. Fixes https://github.com/kubernetes/kubernetes/issues/60443. /cc @kubernetes/sig-node-pr-reviews **Release note**: ```release-note none ```
parents 724a2f96 1fb91cc8
......@@ -124,7 +124,7 @@ func (i *imageCache) set(images []container.Image) {
func (i *imageCache) get() []container.Image {
i.RLock()
defer i.RUnlock()
return i.images
return append([]container.Image{}, i.images...)
}
// Information about the images we track.
......
......@@ -548,6 +548,16 @@ func TestValidateImageGCPolicy(t *testing.T) {
}
}
func TestImageCacheReturnCopiedList(t *testing.T) {
cache := &imageCache{}
testList := []container.Image{{ID: "1"}, {ID: "2"}}
cache.set(testList)
list := cache.get()
assert.Len(t, list, 2)
list[0].ID = "3"
assert.Equal(t, cache.get(), testList)
}
func uint64Ptr(i uint64) *uint64 {
return &i
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment