mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Merge pull request #119986 from ruiwen-zhao/fix_pinned
Pass Pinned field to kubecontainer.Image
This commit is contained in:
commit
f8b5f1a77b
@ -111,6 +111,7 @@ func (m *kubeGenericRuntimeManager) ListImages(ctx context.Context) ([]kubeconta
|
|||||||
RepoTags: img.RepoTags,
|
RepoTags: img.RepoTags,
|
||||||
RepoDigests: img.RepoDigests,
|
RepoDigests: img.RepoDigests,
|
||||||
Spec: toKubeContainerImageSpec(img),
|
Spec: toKubeContainerImageSpec(img),
|
||||||
|
Pinned: img.Pinned,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +101,30 @@ func TestListImages(t *testing.T) {
|
|||||||
assert.Equal(t, expected.List(), actual.List())
|
assert.Equal(t, expected.List(), actual.List())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestListImagesPinnedField(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
_, fakeImageService, fakeManager, err := createTestRuntimeManager()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
imagesPinned := map[string]bool{
|
||||||
|
"1111": false,
|
||||||
|
"2222": true,
|
||||||
|
"3333": false,
|
||||||
|
}
|
||||||
|
imageList := []string{}
|
||||||
|
for image, pinned := range imagesPinned {
|
||||||
|
fakeImageService.SetFakeImagePinned(image, pinned)
|
||||||
|
imageList = append(imageList, image)
|
||||||
|
}
|
||||||
|
fakeImageService.SetFakeImages(imageList)
|
||||||
|
|
||||||
|
actualImages, err := fakeManager.ListImages(ctx)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
for _, image := range actualImages {
|
||||||
|
assert.Equal(t, imagesPinned[image.ID], image.Pinned)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestListImagesWithError(t *testing.T) {
|
func TestListImagesWithError(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, fakeImageService, fakeManager, err := createTestRuntimeManager()
|
_, fakeImageService, fakeManager, err := createTestRuntimeManager()
|
||||||
|
@ -34,6 +34,7 @@ type FakeImageService struct {
|
|||||||
Called []string
|
Called []string
|
||||||
Errors map[string][]error
|
Errors map[string][]error
|
||||||
Images map[string]*runtimeapi.Image
|
Images map[string]*runtimeapi.Image
|
||||||
|
Pinned map[string]bool
|
||||||
|
|
||||||
pulledImages []*pulledImage
|
pulledImages []*pulledImage
|
||||||
|
|
||||||
@ -73,6 +74,17 @@ func (r *FakeImageService) SetFakeImageSize(size uint64) {
|
|||||||
r.FakeImageSize = size
|
r.FakeImageSize = size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetFakeImagePinned sets the image Pinned field for one image.
|
||||||
|
func (r *FakeImageService) SetFakeImagePinned(image string, pinned bool) {
|
||||||
|
r.Lock()
|
||||||
|
defer r.Unlock()
|
||||||
|
|
||||||
|
if r.Pinned == nil {
|
||||||
|
r.Pinned = make(map[string]bool)
|
||||||
|
}
|
||||||
|
r.Pinned[image] = pinned
|
||||||
|
}
|
||||||
|
|
||||||
// SetFakeFilesystemUsage sets the FilesystemUsage for FakeImageService.
|
// SetFakeFilesystemUsage sets the FilesystemUsage for FakeImageService.
|
||||||
func (r *FakeImageService) SetFakeFilesystemUsage(usage []*runtimeapi.FilesystemUsage) {
|
func (r *FakeImageService) SetFakeFilesystemUsage(usage []*runtimeapi.FilesystemUsage) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
@ -96,6 +108,7 @@ func (r *FakeImageService) makeFakeImage(image *runtimeapi.ImageSpec) *runtimeap
|
|||||||
Size_: r.FakeImageSize,
|
Size_: r.FakeImageSize,
|
||||||
Spec: image,
|
Spec: image,
|
||||||
RepoTags: []string{image.Image},
|
RepoTags: []string{image.Image},
|
||||||
|
Pinned: r.Pinned[image.Image],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user