Add a new image label if it is docker schema 1
Signed-off-by: Qiutong Song <songqt01@gmail.com>
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
goruntime "runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -234,3 +236,41 @@ func TestContainerdSandboxImage(t *testing.T) {
|
||||
t.Log("verify pinned field is set for pause image")
|
||||
assert.True(t, pimg.Pinned)
|
||||
}
|
||||
|
||||
func TestContainerdImageWithDockerSchema1(t *testing.T) {
|
||||
if goruntime.GOOS == "windows" {
|
||||
t.Skip("Skipped on Windows because the test image is not a multi-platform one.")
|
||||
}
|
||||
|
||||
var testImage = images.Get(images.DockerSchema1)
|
||||
digest := strings.Split(testImage, "@")[1]
|
||||
ctx := context.Background()
|
||||
|
||||
t.Logf("make sure the test image doesn't exist in the cri plugin")
|
||||
i, err := imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
|
||||
require.NoError(t, err)
|
||||
if i != nil {
|
||||
require.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: testImage}))
|
||||
}
|
||||
|
||||
t.Logf("pull the image into containerd")
|
||||
//nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
|
||||
_, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithSchema1Conversion)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
// Make sure the image is cleaned up in any case.
|
||||
if err := containerdClient.ImageService().Delete(ctx, testImage); err != nil {
|
||||
assert.True(t, errdefs.IsNotFound(err), err)
|
||||
}
|
||||
assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: testImage}))
|
||||
}()
|
||||
|
||||
imgByRef, err := containerdClient.GetImage(ctx, testImage)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf("the image should be marked as managed")
|
||||
assert.Equal(t, "managed", imgByRef.Labels()["io.cri-containerd.image"])
|
||||
|
||||
t.Logf("the image should be marked as dokcker schema1 with its original digest")
|
||||
assert.Equal(t, digest, imgByRef.Labels()["io.containerd.image/converted-docker-schema1"])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user