@@ -21,76 +21,70 @@ import (
21
21
"testing"
22
22
23
23
"github.com/containerd/nerdctl/v2/pkg/testutil"
24
+ "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
25
+ "github.com/containerd/nerdctl/v2/pkg/testutil/test"
24
26
)
25
27
26
- /*
27
- This test below is meant to assert that https://github.com/containerd/nerdctl/issues/827 is NOT fixed.
28
- Obviously, once we fix the issue, it should be replaced by something that assert it works.
29
- Unfortunately, this is flaky.
30
- It will regularly succeed or fail, making random PR fail the Kube check.
31
- */
32
-
33
- func TestKubeCommitPush (t * testing.T ) {
34
- t .Parallel ()
35
-
36
- base := testutil .NewBaseForKubernetes (t )
37
- tID := testutil .Identifier (t )
38
-
39
- var containerID string
40
- // var registryIP string
41
-
42
- setup := func () {
43
- testutil .KubectlHelper (base , "run" , "--image" , testutil .CommonImage , tID , "--" , "sleep" , "Inf" ).
44
- AssertOK ()
45
-
46
- testutil .KubectlHelper (base , "wait" , "pod" , tID , "--for=condition=ready" , "--timeout=1m" ).
47
- AssertOK ()
48
-
49
- testutil .KubectlHelper (base , "exec" , tID , "--" , "mkdir" , "-p" , "/tmp/whatever" ).
50
- AssertOK ()
51
-
52
- cmd := testutil .KubectlHelper (base , "get" , "pods" , tID , "-o" , "jsonpath={ .status.containerStatuses[0].containerID }" )
53
- cmd .Run ()
54
- containerID = strings .TrimPrefix (cmd .Out (), "containerd://" )
55
-
56
- // This below is missing configuration to allow for plain http communication
57
- // This is left here for future work to successfully start a registry usable in the cluster
58
- /*
59
- // Start a registry
60
- testutil.KubectlHelper(base, "run", "--port", "5000", "--image", testutil.RegistryImageStable, "testregistry").
61
- AssertOK()
62
-
63
- testutil.KubectlHelper(base, "wait", "pod", "testregistry", "--for=condition=ready", "--timeout=1m").
64
- AssertOK()
65
-
66
- cmd = testutil.KubectlHelper(base, "get", "pods", tID, "-o", "jsonpath={ .status.hostIPs[0].ip }")
67
- cmd.Run()
68
- registryIP = cmd.Out()
69
-
70
- cmd = testutil.KubectlHelper(base, "apply", "-f", "-", fmt.Sprintf(`apiVersion: v1
71
- kind: ConfigMap
72
- metadata:
73
- name: local-registry
74
- namespace: nerdctl-test
75
- data:
76
- localRegistryHosting.v1: |
77
- host: "%s:5000"
78
- help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
79
- `, registryIP))
80
- */
81
-
28
+ func TestKubeCommitSave (t * testing.T ) {
29
+ testCase := nerdtest .Setup ()
30
+
31
+ testCase .Require = nerdtest .OnlyKubernetes
32
+
33
+ testCase .Setup = func (data test.Data , helpers test.Helpers ) {
34
+ containerID := ""
35
+ // NOTE: kubectl namespaces are not the same as containerd namespaces.
36
+ // We still want kube test objects segregated in their own Kube API namespace.
37
+ nerdtest .KubeCtlCommand (helpers , "create" , "namespace" , "nerdctl-test-k8s" ).Run (& test.Expected {})
38
+ nerdtest .KubeCtlCommand (helpers , "run" , "--image" , testutil .CommonImage , data .Identifier (), "--" , "sleep" , "Inf" ).Run (& test.Expected {})
39
+ nerdtest .KubeCtlCommand (helpers , "wait" , "pod" , data .Identifier (), "--for=condition=ready" , "--timeout=1m" ).Run (& test.Expected {})
40
+ nerdtest .KubeCtlCommand (helpers , "exec" , data .Identifier (), "--" , "mkdir" , "-p" , "/tmp/whatever" ).Run (& test.Expected {})
41
+ nerdtest .KubeCtlCommand (helpers , "get" , "pods" , data .Identifier (), "-o" , "jsonpath={ .status.containerStatuses[0].containerID }" ).Run (& test.Expected {
42
+ Output : func (stdout string , info string , t * testing.T ) {
43
+ containerID = strings .TrimPrefix (stdout , "containerd://" )
44
+ },
45
+ })
46
+ data .Set ("containerID" , containerID )
82
47
}
83
48
84
- tearDown : = func () {
85
- testutil . KubectlHelper ( base , "delete" , "pod" , "--all" ).Run ()
49
+ testCase . Cleanup = func (data test. Data , helpers test. Helpers ) {
50
+ nerdtest . KubeCtlCommand ( helpers , "delete" , "pod" , "--all" ).Run (nil )
86
51
}
87
52
88
- tearDown ()
89
- t .Cleanup (tearDown )
90
- setup ()
53
+ testCase .Command = func (data test.Data , helpers test.Helpers ) test.TestableCommand {
54
+ helpers .Ensure ("commit" , data .Get ("containerID" ), "testcommitsave" )
55
+ return helpers .Command ("save" , "testcommitsave" )
56
+ }
91
57
92
- t .Run ("test commit / push on Kube (https://github.com/containerd/nerdctl/issues/827)" , func (t * testing.T ) {
93
- base .Cmd ("commit" , containerID , "testcommitsave" ).AssertOK ()
94
- base .Cmd ("save" , "testcommitsave" ).AssertOK ()
95
- })
58
+ testCase .Expected = test .Expects (0 , nil , nil )
59
+
60
+ testCase .Run (t )
61
+
62
+ // This below is missing configuration to allow for plain http communication
63
+ // This is left here for future work to successfully start a registry usable in the cluster
64
+ /*
65
+ // Start a registry
66
+ nerdtest.KubeCtlCommand(helpers, "run", "--port", "5000", "--image", testutil.RegistryImageStable, "testregistry").
67
+ Run(&test.Expected{})
68
+
69
+ nerdtest.KubeCtlCommand(helpers, "wait", "pod", "testregistry", "--for=condition=ready", "--timeout=1m").
70
+ AssertOK()
71
+
72
+ cmd = nerdtest.KubeCtlCommand(helpers, "get", "pods", tID, "-o", "jsonpath={ .status.hostIPs[0].ip }")
73
+ cmd.Run(&test.Expected{
74
+ Output: func(stdout string, info string, t *testing.T) {
75
+ registryIP = stdout
76
+ },
77
+ })
78
+
79
+ cmd = nerdtest.KubeCtlCommand(helpers, "apply", "-f", "-", fmt.Sprintf(`apiVersion: v1
80
+ kind: ConfigMap
81
+ metadata:
82
+ name: local-registry
83
+ namespace: nerdctl-test
84
+ data:
85
+ localRegistryHosting.v1: |
86
+ host: "%s:5000"
87
+ help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
88
+ `, registryIP))
89
+ */
96
90
}
0 commit comments