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

Pass Pinned field to kubecontainer.Image #119986

Merged
merged 1 commit into from
Aug 18, 2023
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
Original file line number Diff line number Diff line change
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

})
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/kubelet/kuberuntime/kuberuntime_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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
Original file line number Diff line number Diff line change
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