Skip to content

Commit

Permalink
Fix tests and add regression tests for containerd#3425
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Sep 25, 2024
1 parent 1e52bf5 commit 764a2aa
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 143 deletions.
46 changes: 31 additions & 15 deletions cmd/nerdctl/container/container_commit_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"strings"
"testing"

"gotest.tools/v3/icmd"

"github.com/containerd/nerdctl/v2/pkg/testutil"
)

Expand All @@ -35,12 +33,11 @@ It will regularly succeed or fail, making random PR fail the Kube check.
func TestKubeCommitPush(t *testing.T) {
t.Parallel()

t.Skip("Test that confirm that #827 is still broken is too flaky")

base := testutil.NewBaseForKubernetes(t)
tID := testutil.Identifier(t)

var containerID string
// var registryIP string

setup := func() {
testutil.KubectlHelper(base, "run", "--image", testutil.CommonImage, tID, "--", "sleep", "Inf").
Expand All @@ -55,26 +52,45 @@ func TestKubeCommitPush(t *testing.T) {
cmd := testutil.KubectlHelper(base, "get", "pods", tID, "-o", "jsonpath={ .status.containerStatuses[0].containerID }")
cmd.Run()
containerID = strings.TrimPrefix(cmd.Out(), "containerd://")

// This below is missing configuration to allow for plain http communication
// This is left here for future work to successfully start a registry usable in the cluster
/*
// Start a registry
testutil.KubectlHelper(base, "run", "--port", "5000", "--image", testutil.RegistryImageStable, "testregistry").
AssertOK()
testutil.KubectlHelper(base, "wait", "pod", "testregistry", "--for=condition=ready", "--timeout=1m").
AssertOK()
cmd = testutil.KubectlHelper(base, "get", "pods", tID, "-o", "jsonpath={ .status.hostIPs[0].ip }")
cmd.Run()
registryIP = cmd.Out()
cmd = testutil.KubectlHelper(base, "apply", "-f", "-", fmt.Sprintf(`apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry
namespace: nerdctl-test
data:
localRegistryHosting.v1: |
host: "%s:5000"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
`, registryIP))
*/

}

tearDown := func() {
testutil.KubectlHelper(base, "delete", "pod", "-f", tID).Run()
testutil.KubectlHelper(base, "delete", "pod", "--all").Run()
}

tearDown()
t.Cleanup(tearDown)
setup()

t.Run("test commit / push on Kube (https://github.com/containerd/nerdctl/issues/827)", func(t *testing.T) {
t.Log("This test is meant to verify that we can commit / push an image from a pod." +
"Currently, this is broken, hence the test assumes it will fail. Once the problem is fixed, we should just" +
"change the expectation to 'success'.")

base.Cmd("commit", containerID, "registry.example.com/my-app:v1").AssertOK()
// See note above.
base.Cmd("push", "registry.example.com/my-app:v1").Assert(icmd.Expected{
ExitCode: 1,
Err: "failed to create a tmp single-platform image",
})
base.Cmd("commit", containerID, "testcommitsave").AssertOK()
base.Cmd("save", "testcommitsave").AssertOK()
})
}
Loading

0 comments on commit 764a2aa

Please sign in to comment.