Skip to content

Commit

Permalink
cri: fix using the pinned label to pin image
Browse files Browse the repository at this point in the history
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
  • Loading branch information
Iceber committed Jul 26, 2023
1 parent 8348a8c commit 7f7ba31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion integration/containerd_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/integration/images"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/cri/labels"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
Expand All @@ -45,7 +46,8 @@ func TestContainerdImage(t *testing.T) {
}

t.Logf("pull the image into containerd")
_, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithPullLabel("foo", "bar"))
lbs := map[string]string{"foo": "bar", labels.PinnedImageLabelKey: labels.PinnedImageLabelValue}
_, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithPullLabels(lbs))
assert.NoError(t, err)
defer func() {
// Make sure the image is cleaned up in any case.
Expand Down Expand Up @@ -126,6 +128,13 @@ func TestContainerdImage(t *testing.T) {
img, err := containerdClient.GetImage(ctx, testImage)
assert.NoError(t, err)
assert.Equal(t, img.Labels()["foo"], "bar")
assert.Equal(t, img.Labels()[labels.ImageLabelKey], labels.ImageLabelValue)

t.Logf("the image should be pinned")
i, err = imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
require.NoError(t, err)
require.NotNil(t, i)
assert.True(t, i.Pinned)

t.Logf("should be able to start container with the image")
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "containerd-image")
Expand Down
1 change: 1 addition & 0 deletions pkg/cri/store/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (s *store) add(img Image) error {
}
// Or else, merge and sort the references.
i.References = docker.Sort(util.MergeStringSlices(i.References, img.References))
i.Pinned = i.Pinned || img.Pinned
s.images[img.ID] = i
return nil
}
Expand Down

0 comments on commit 7f7ba31

Please sign in to comment.