Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #119986: Pass Pinned field to kubecontainer.Image #120054

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/kubelet/kuberuntime/kuberuntime_image.go
Expand Up @@ -111,6 +111,7 @@ func (m *kubeGenericRuntimeManager) ListImages(ctx context.Context) ([]kubeconta
RepoTags: img.RepoTags,
RepoDigests: img.RepoDigests,
Spec: toKubeContainerImageSpec(img),
Pinned: img.Pinned,
})
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/kubelet/kuberuntime/kuberuntime_image_test.go
Expand Up @@ -86,6 +86,30 @@ func TestListImages(t *testing.T) {
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) {
ctx := context.Background()
_, fakeImageService, fakeManager, err := createTestRuntimeManager()
Expand Down
13 changes: 13 additions & 0 deletions staging/src/k8s.io/cri-api/pkg/apis/testing/fake_image_service.go
Expand Up @@ -34,6 +34,7 @@ type FakeImageService struct {
Called []string
Errors map[string][]error
Images map[string]*runtimeapi.Image
Pinned map[string]bool

pulledImages []*pulledImage

Expand Down Expand Up @@ -73,6 +74,17 @@ func (r *FakeImageService) SetFakeImageSize(size uint64) {
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.
func (r *FakeImageService) SetFakeFilesystemUsage(usage []*runtimeapi.FilesystemUsage) {
r.Lock()
Expand All @@ -96,6 +108,7 @@ func (r *FakeImageService) makeFakeImage(image *runtimeapi.ImageSpec) *runtimeap
Size_: r.FakeImageSize,
Spec: image,
RepoTags: []string{image.Image},
Pinned: r.Pinned[image.Image],
}
}

Expand Down