Skip to content

Commit 73ca29c

Browse files
Merge pull request #29594 from bitoku/nested-container
OCPNODE-2315: Add nested container test
2 parents 590f8e9 + a3d72ad commit 73ca29c

File tree

10 files changed

+626
-0
lines changed

10 files changed

+626
-0
lines changed

pkg/testsuites/standard_suites.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,4 +436,17 @@ var staticSuites = []ginkgo.TestSuite{
436436
},
437437
TestTimeout: 30 * time.Minute,
438438
},
439+
{
440+
Name: "openshift/usernamespace",
441+
Description: templates.LongDesc(`
442+
This test suite runs tests to validate user namespace functionality.
443+
`),
444+
Matches: func(name string) bool {
445+
if isDisabled(name) {
446+
return false
447+
}
448+
return strings.Contains(name, "[Suite:openshift/usernamespace")
449+
},
450+
TestTimeout: 60 * time.Minute,
451+
},
439452
}

test/extended/include.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
_ "github.com/openshift/origin/test/extended/machine_config"
4242
_ "github.com/openshift/origin/test/extended/machines"
4343
_ "github.com/openshift/origin/test/extended/networking"
44+
_ "github.com/openshift/origin/test/extended/node"
4445
_ "github.com/openshift/origin/test/extended/node_tuning"
4546
_ "github.com/openshift/origin/test/extended/oauth"
4647
_ "github.com/openshift/origin/test/extended/olm"
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package node
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
g "github.com/onsi/ginkgo/v2"
9+
o "github.com/onsi/gomega"
10+
exutil "github.com/openshift/origin/test/extended/util"
11+
corev1 "k8s.io/api/core/v1"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
admissionapi "k8s.io/pod-security-admission/api"
14+
"k8s.io/utils/pointer"
15+
"k8s.io/utils/ptr"
16+
)
17+
18+
var (
19+
oc = exutil.NewCLIWithPodSecurityLevel("nested-podman", admissionapi.LevelBaseline)
20+
name = "baseline-nested-container"
21+
customImage = exutil.FixturePath("testdata", "node", "nested_container")
22+
)
23+
24+
var _ = g.Describe("[Suite:openshift/usernamespace] [sig-node] [FeatureGate:ProcMountType] [FeatureGate:UserNamespacesSupport] nested container", func() {
25+
g.It("should pass podman localsystem test in baseline mode",
26+
func(ctx context.Context) {
27+
if !exutil.IsTechPreviewNoUpgrade(ctx, oc.AdminConfigClient()) {
28+
g.Skip("skipping, this feature is only supported on TechPreviewNoUpgrade clusters")
29+
}
30+
runNestedPod(ctx)
31+
},
32+
)
33+
})
34+
35+
func runNestedPod(ctx context.Context) {
36+
g.By("creating custom builder image")
37+
err := oc.Run("new-build").Args("--binary", "--strategy=docker", fmt.Sprintf("--name=%s", name)).Execute()
38+
o.Expect(err).NotTo(o.HaveOccurred())
39+
br, _ := exutil.StartBuildAndWait(oc, name, fmt.Sprintf("--from-dir=%s", customImage))
40+
br.AssertSuccess()
41+
42+
g.By("creating a pod with a nested container")
43+
namespace := oc.Namespace()
44+
pod := &corev1.Pod{
45+
TypeMeta: metav1.TypeMeta{
46+
APIVersion: "v1",
47+
Kind: "Pod",
48+
},
49+
ObjectMeta: metav1.ObjectMeta{
50+
Name: name,
51+
Annotations: map[string]string{
52+
"io.kubernetes.cri-o.Devices": "/dev/fuse,/dev/net/tun",
53+
},
54+
},
55+
Spec: corev1.PodSpec{
56+
HostUsers: pointer.Bool(false),
57+
DNSPolicy: corev1.DNSNone,
58+
DNSConfig: &corev1.PodDNSConfig{
59+
Nameservers: []string{"1.1.1.1"},
60+
},
61+
RestartPolicy: corev1.RestartPolicyNever,
62+
Containers: []corev1.Container{
63+
{
64+
Name: "nested-podman",
65+
Image: fmt.Sprintf("image-registry.openshift-image-registry.svc:5000/%s/%s", namespace, name),
66+
ImagePullPolicy: corev1.PullAlways,
67+
Args: []string{
68+
"./run_tests.sh",
69+
},
70+
SecurityContext: &corev1.SecurityContext{
71+
RunAsUser: pointer.Int64(1000),
72+
ProcMount: ptr.To(corev1.UnmaskedProcMount),
73+
Capabilities: &corev1.Capabilities{
74+
Add: []corev1.Capability{
75+
"SETUID",
76+
"SETGID",
77+
},
78+
},
79+
SELinuxOptions: &corev1.SELinuxOptions{
80+
Type: "container_engine_t",
81+
},
82+
},
83+
},
84+
},
85+
},
86+
}
87+
_, err = oc.AsAdmin().KubeClient().CoreV1().Pods(namespace).Create(ctx, pod, metav1.CreateOptions{})
88+
o.Expect(err).NotTo(o.HaveOccurred())
89+
90+
g.By("waiting for the pod to complete")
91+
o.Eventually(func() error {
92+
_, err := oc.AsAdmin().Run("exec").Args(pod.Name, "--", "[", "-f", "done", "]").Output()
93+
if err != nil {
94+
return err
95+
}
96+
return nil
97+
}, "30m", "10s").Should(o.Succeed())
98+
99+
// To upload test results from podman system test, use ARTIFACT_DIR env var.
100+
// It's not a smart way, but there's no other way to pass the artifact directory
101+
// to each test case.
102+
g.By("uploading results from podman system test")
103+
artifact := os.Getenv("ARTIFACT_DIR")
104+
_, err = oc.AsAdmin().Run("cp").Args(
105+
fmt.Sprintf("%s:serial-junit/report.xml", pod.Name),
106+
fmt.Sprintf("%s/junit/podman-system-serial.xml", artifact),
107+
).Output()
108+
o.Expect(err).NotTo(o.HaveOccurred())
109+
_, err = oc.AsAdmin().Run("cp").Args(
110+
fmt.Sprintf("%s:parallel-junit/report.xml", pod.Name),
111+
fmt.Sprintf("%s/junit/podman-system-parallel.xml", artifact),
112+
).Output()
113+
o.Expect(err).NotTo(o.HaveOccurred())
114+
115+
logs, err := oc.AsAdmin().KubeClient().CoreV1().Pods(namespace).GetLogs(pod.Name, &corev1.PodLogOptions{}).Do(ctx).Raw()
116+
o.Expect(err).NotTo(o.HaveOccurred())
117+
118+
_, err = oc.AsAdmin().Run("exec").Args(pod.Name, "--", "[", "!", "-f", "fail", "]").Output()
119+
o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("more than one of the podman system tests failed:\n%s", logs))
120+
}

0 commit comments

Comments
 (0)