Merge pull request #8867 from Iceber/pinned_image_label
cri: fix using the labels to pin image
This commit is contained in:
commit
81895d22c9
@ -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"
|
||||
@ -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.
|
||||
@ -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")
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user