Skip to content

Commit 751b0c1

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 e01706e commit 751b0c1

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"
2828
"github.com/containerd/containerd/errdefs"
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
"golang.org/x/net/context"
@@ -46,7 +47,8 @@ func TestContainerdImage(t *testing.T) {
4647
}
4748

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

131140
t.Logf("should be able to start container with the image")
132141
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
@@ -218,6 +218,7 @@ func (s *store) add(img Image) error {
218218
}
219219
// Or else, merge and sort the references.
220220
i.References = sortReferences(util.MergeStringSlices(i.References, img.References))
221+
i.Pinned = i.Pinned || img.Pinned
221222
s.images[img.ID] = i
222223
return nil
223224
}

0 commit comments

Comments
 (0)