Skip to content

Commit a20a822

Browse files
e2e_node: skip proc mount tests on nodes without userns support in the runtime
Signed-off-by: Peter Hunt <[email protected]> Co-authored-by: Sohan Kunkerkar <[email protected]>
1 parent 4f57a14 commit a20a822

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/e2e_node/proc_mount_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/kubernetes/test/e2e/feature"
2929
"k8s.io/kubernetes/test/e2e/framework"
3030
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
31+
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
3132
"k8s.io/kubernetes/test/e2e/nodefeature"
3233
testutils "k8s.io/kubernetes/test/utils"
3334
imageutils "k8s.io/kubernetes/test/utils/image"
@@ -50,6 +51,9 @@ var _ = SIGDescribe("ProcMount [LinuxOnly]", nodefeature.ProcMountType, nodefeat
5051
f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
5152

5253
f.It("will fail to unmask proc mounts if not privileged", func(ctx context.Context) {
54+
if !supportsUserNS(ctx, f) {
55+
e2eskipper.Skipf("runtime does not support user namespaces")
56+
}
5357
pmt := v1.UnmaskedProcMount
5458
podClient := e2epod.NewPodClient(f)
5559
_, err := podClient.PodInterface.Create(ctx, &v1.Pod{
@@ -79,6 +83,9 @@ var _ = SIGDescribe("ProcMount [LinuxOnly]", nodefeature.ProcMountType, nodefeat
7983
f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
8084

8185
f.It("will unmask proc mounts if requested", func(ctx context.Context) {
86+
if !supportsUserNS(ctx, f) {
87+
e2eskipper.Skipf("runtime does not support user namespaces")
88+
}
8289
testProcMount(ctx, f, v1.UnmaskedProcMount, gomega.Equal(1), gomega.BeZero())
8390
})
8491
})
@@ -113,3 +120,17 @@ func testProcMount(ctx context.Context, f *framework.Framework, pmt v1.ProcMount
113120
gomega.Expect(len(lines)).To(expectedLines)
114121
gomega.Expect(strings.Count(output, "(ro")).To(expectedReadOnly)
115122
}
123+
124+
func supportsUserNS(ctx context.Context, f *framework.Framework) bool {
125+
nodeList, err := f.ClientSet.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
126+
framework.ExpectNoError(err)
127+
// Assuming that there is only one node, because this is a node e2e test.
128+
gomega.Expect(nodeList.Items).To(gomega.HaveLen(1))
129+
node := nodeList.Items[0]
130+
for _, rc := range node.Status.RuntimeHandlers {
131+
if rc.Name == "" && rc.Features != nil && *rc.Features.UserNamespaces {
132+
return true
133+
}
134+
}
135+
return false
136+
}

0 commit comments

Comments
 (0)