From faa28f89f872c7df9c70aef5722c76f9088bdc86 Mon Sep 17 00:00:00 2001 From: apostasie Date: Thu, 4 Jul 2024 20:50:24 -0700 Subject: [PATCH] Workaround flaky save Signed-off-by: apostasie --- cmd/nerdctl/container_run_linux_test.go | 14 +++++++++++++- cmd/nerdctl/image_save_linux_test.go | 6 +++++- cmd/nerdctl/image_save_test.go | 12 ++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cmd/nerdctl/container_run_linux_test.go b/cmd/nerdctl/container_run_linux_test.go index 15b17ab614c..f85c5618c79 100644 --- a/cmd/nerdctl/container_run_linux_test.go +++ b/cmd/nerdctl/container_run_linux_test.go @@ -42,8 +42,20 @@ import ( func TestRunCustomRootfs(t *testing.T) { testutil.DockerIncompatible(t) - base := testutil.NewBase(t) + // FIXME: root issue is undiagnosed and this is very likely a containerd bug + // It appears that in certain conditions, the proxy content store info method will fail on the layer of the image + // Search for func (pcs *proxyContentStore) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) { + // Note that: + // - the problem is still here with containerd and nerdctl v2 + // - it seems to affect images that are tagged multiple times, or that share a layer with another image + // - this test is not parallelized - but the fact that namespacing it solves the problem suggest that something + // happening in the default namespace BEFORE this test is run is SOMETIMES setting conditions that will make this fail + // Possible suspects would be concurrent pulls somehow effing things up w. namespaces. + base := testutil.NewBaseWithNamespace(t, testutil.Identifier(t)) rootfs := prepareCustomRootfs(base, testutil.AlpineImage) + t.Cleanup(func() { + base.Cmd("namespace", "remove", testutil.Identifier(t)).Run() + }) defer os.RemoveAll(rootfs) base.Cmd("run", "--rm", "--rootfs", rootfs, "/bin/cat", "/proc/self/environ").AssertOutContains("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") base.Cmd("run", "--rm", "--entrypoint", "/bin/echo", "--rootfs", rootfs, "echo", "foo").AssertOutExactly("echo foo\n") diff --git a/cmd/nerdctl/image_save_linux_test.go b/cmd/nerdctl/image_save_linux_test.go index be9504ca5d4..82072f46623 100644 --- a/cmd/nerdctl/image_save_linux_test.go +++ b/cmd/nerdctl/image_save_linux_test.go @@ -32,7 +32,11 @@ import ( ) func TestSave(t *testing.T) { - base := testutil.NewBase(t) + // See detailed comment in TestRunCustomRootfs for why we need a separate namespace. + base := testutil.NewBaseWithNamespace(t, testutil.Identifier(t)) + t.Cleanup(func() { + base.Cmd("namespace", "remove", testutil.Identifier(t)).Run() + }) base.Cmd("pull", testutil.AlpineImage).AssertOK() archiveTarPath := filepath.Join(t.TempDir(), "a.tar") base.Cmd("save", "-o", archiveTarPath, testutil.AlpineImage).AssertOK() diff --git a/cmd/nerdctl/image_save_test.go b/cmd/nerdctl/image_save_test.go index 2bfdeeeb2c1..4b37a497b93 100644 --- a/cmd/nerdctl/image_save_test.go +++ b/cmd/nerdctl/image_save_test.go @@ -25,7 +25,11 @@ import ( ) func TestSaveById(t *testing.T) { - base := testutil.NewBase(t) + // See detailed comment in TestRunCustomRootfs for why we need a separate namespace. + base := testutil.NewBaseWithNamespace(t, testutil.Identifier(t)) + t.Cleanup(func() { + base.Cmd("namespace", "remove", testutil.Identifier(t)).Run() + }) base.Cmd("pull", testutil.CommonImage).AssertOK() inspect := base.InspectImage(testutil.CommonImage) var id string @@ -42,7 +46,11 @@ func TestSaveById(t *testing.T) { } func TestSaveByIdWithDifferentNames(t *testing.T) { - base := testutil.NewBase(t) + // See detailed comment in TestRunCustomRootfs for why we need a separate namespace. + base := testutil.NewBaseWithNamespace(t, testutil.Identifier(t)) + t.Cleanup(func() { + base.Cmd("namespace", "remove", testutil.Identifier(t)).Run() + }) base.Cmd("pull", testutil.CommonImage).AssertOK() inspect := base.InspectImage(testutil.CommonImage) var id string