|
@@ -10,6 +10,7 @@ import (
|
|
"testing"
|
|
"testing"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
+ "github.com/containerd/containerd"
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/api/types/network"
|
|
"github.com/docker/docker/api/types/network"
|
|
"github.com/docker/docker/api/types/versions"
|
|
"github.com/docker/docker/api/types/versions"
|
|
@@ -668,3 +669,40 @@ func TestCreateWithCustomMACs(t *testing.T) {
|
|
assert.Equal(t, mac, "02:32:1c:23:00:04")
|
|
assert.Equal(t, mac, "02:32:1c:23:00:04")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// Tests that when using containerd backed storage the containerd container has the image referenced stored.
|
|
|
|
+func TestContainerdContainerImageInfo(t *testing.T) {
|
|
|
|
+ skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.45"), "requires API v1.45")
|
|
|
|
+
|
|
|
|
+ ctx := setupTest(t)
|
|
|
|
+
|
|
|
|
+ apiClient := testEnv.APIClient()
|
|
|
|
+ defer apiClient.Close()
|
|
|
|
+
|
|
|
|
+ info, err := apiClient.Info(ctx)
|
|
|
|
+ assert.NilError(t, err)
|
|
|
|
+
|
|
|
|
+ skip.If(t, info.Containerd == nil, "requires containerd")
|
|
|
|
+
|
|
|
|
+ // Currently a containerd container is only created when the container is started.
|
|
|
|
+ // So start the container and then inspect the containerd container to verify the image info.
|
|
|
|
+ id := ctr.Run(ctx, t, apiClient, func(cfg *ctr.TestContainerConfig) {
|
|
|
|
+ // busybox is the default (as of this writing) used by the test client, but lets be explicit here.
|
|
|
|
+ cfg.Config.Image = "busybox"
|
|
|
|
+ })
|
|
|
|
+ defer apiClient.ContainerRemove(ctx, id, container.RemoveOptions{Force: true})
|
|
|
|
+
|
|
|
|
+ client, err := containerd.New(info.Containerd.Address, containerd.WithDefaultNamespace(info.Containerd.Namespaces.Containers))
|
|
|
|
+ assert.NilError(t, err)
|
|
|
|
+ defer client.Close()
|
|
|
|
+
|
|
|
|
+ ctr, err := client.ContainerService().Get(ctx, id)
|
|
|
|
+ assert.NilError(t, err)
|
|
|
|
+
|
|
|
|
+ if testEnv.UsingSnapshotter() {
|
|
|
|
+ assert.Equal(t, ctr.Image, "docker.io/library/busybox:latest")
|
|
|
|
+ } else {
|
|
|
|
+ // This field is not set when not using contianerd backed storage.
|
|
|
|
+ assert.Equal(t, ctr.Image, "")
|
|
|
|
+ }
|
|
|
|
+}
|