Skip to content

Commit 7f7ba31

Browse files
committed
cri: fix using the pinned label to pin image
Signed-off-by: Iceber Gu <[email protected]>
1 parent 8348a8c commit 7f7ba31

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

integration/containerd_image_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/containerd/containerd/errdefs"
2828
"github.com/containerd/containerd/integration/images"
2929
"github.com/containerd/containerd/namespaces"
30+
"github.com/containerd/containerd/pkg/cri/labels"
3031
"github.com/stretchr/testify/assert"
3132
"github.com/stretchr/testify/require"
3233
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -45,7 +46,8 @@ func TestContainerdImage(t *testing.T) {
4546
}
4647

4748
t.Logf("pull the image into containerd")
48-
_, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithPullLabel("foo", "bar"))
49+
lbs := map[string]string{"foo": "bar", labels.PinnedImageLabelKey: labels.PinnedImageLabelValue}
50+
_, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithPullLabels(lbs))
4951
assert.NoError(t, err)
5052
defer func() {
5153
// Make sure the image is cleaned up in any case.
@@ -126,6 +128,13 @@ func TestContainerdImage(t *testing.T) {
126128
img, err := containerdClient.GetImage(ctx, testImage)
127129
assert.NoError(t, err)
128130
assert.Equal(t, img.Labels()["foo"], "bar")
131+
assert.Equal(t, img.Labels()[labels.ImageLabelKey], labels.ImageLabelValue)
132+
133+
t.Logf("the image should be pinned")
134+
i, err = imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
135+
require.NoError(t, err)
136+
require.NotNil(t, i)
137+
assert.True(t, i.Pinned)
129138

130139
t.Logf("should be able to start container with the image")
131140
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "containerd-image")

pkg/cri/store/image/image.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (s *store) add(img Image) error {
213213
}
214214
// Or else, merge and sort the references.
215215
i.References = docker.Sort(util.MergeStringSlices(i.References, img.References))
216+
i.Pinned = i.Pinned || img.Pinned
216217
s.images[img.ID] = i
217218
return nil
218219
}

0 commit comments

Comments
 (0)