Skip to content

Commit

Permalink
Pass Pinned field to kubecontainer.Image
Browse files Browse the repository at this point in the history
Signed-off-by: ruiwen-zhao <ruiwen@google.com>
  • Loading branch information
ruiwen-zhao committed Aug 18, 2023
1 parent 81c519f commit 946ac1d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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,
})
}

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 @@ -81,6 +81,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

0 comments on commit 946ac1d

Please sign in to comment.