Skip to content

Commit 8dc8618

Browse files
committed
cri: fix using the pinned label to pin image
Signed-off-by: Iceber Gu <[email protected]> (cherry picked from commit 7f7ba31) Signed-off-by: Iceber Gu <[email protected]>
1 parent 4f03e10 commit 8dc8618

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
@@ -29,6 +29,7 @@ import (
2929
"github.com/containerd/containerd/errdefs"
3030
"github.com/containerd/containerd/integration/images"
3131
"github.com/containerd/containerd/namespaces"
32+
"github.com/containerd/containerd/pkg/cri/labels"
3233
"github.com/stretchr/testify/assert"
3334
"github.com/stretchr/testify/require"
3435
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -47,7 +48,8 @@ func TestContainerdImage(t *testing.T) {
4748
}
4849

4950
t.Logf("pull the image into containerd")
50-
_, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithPullLabel("foo", "bar"))
51+
lbs := map[string]string{"foo": "bar", labels.PinnedImageLabelKey: labels.PinnedImageLabelValue}
52+
_, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithPullLabels(lbs))
5153
assert.NoError(t, err)
5254
defer func() {
5355
// Make sure the image is cleaned up in any case.
@@ -128,6 +130,13 @@ func TestContainerdImage(t *testing.T) {
128130
img, err := containerdClient.GetImage(ctx, testImage)
129131
assert.NoError(t, err)
130132
assert.Equal(t, img.Labels()["foo"], "bar")
133+
assert.Equal(t, img.Labels()[labels.ImageLabelKey], labels.ImageLabelValue)
134+
135+
t.Logf("the image should be pinned")
136+
i, err = imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
137+
require.NoError(t, err)
138+
require.NotNil(t, i)
139+
assert.True(t, i.Pinned)
131140

132141
t.Logf("should be able to start container with the image")
133142
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)