Skip to content

Commit 0fb028c

Browse files
committed
Migrate OCP-80983: verify cgroupv2 is default and v1 cannot be set
1 parent 2fa0e14 commit 0fb028c

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

test/extended/node/node_e2e/node.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
g "github.com/onsi/ginkgo/v2"
88
o "github.com/onsi/gomega"
9+
910
exutil "github.com/openshift/origin/test/extended/util"
1011
"k8s.io/apimachinery/pkg/util/wait"
1112
e2e "k8s.io/kubernetes/test/e2e/framework"
@@ -74,4 +75,24 @@ var _ = g.Describe("[sig-node] [Jira:Node/Kubelet] Kubelet, CRI-O, CPU manager",
7475
}
7576
o.Expect(waitErr).NotTo(o.HaveOccurred(), "KUBELET_LOG_LEVEL is not expected, timed out")
7677
})
78+
79+
//author: cmaurya@redhat.com
80+
g.It("[OTP] validate cgroupv2 is default", func() {
81+
isMicroShift, err := exutil.IsMicroShiftCluster(oc.AdminKubeClient())
82+
if err != nil {
83+
o.Expect(err).NotTo(o.HaveOccurred(), "error determining if running on MicroShift: %v", err)
84+
}
85+
if isMicroShift {
86+
g.Skip("This test case is not supported in microshift cluster")
87+
}
88+
89+
g.By("1) Check cgroup version")
90+
cgroupV := getCgroupVersion(oc)
91+
o.Expect(strings.Contains(cgroupV, "cgroup2fs")).Should(o.BeTrue())
92+
93+
g.By("2) Changing cgroup from v2 to v1 should result in error")
94+
output, err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("nodes.config.openshift.io", "cluster", "-p", `{"spec": {"cgroupMode": "v1"}}`, "--type=merge").Output()
95+
o.Expect(err).Should(o.HaveOccurred())
96+
o.Expect(strings.Contains(output, "Unsupported value: \"v1\"")).Should(o.BeTrue())
97+
})
7798
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package node
2+
3+
import (
4+
"strings"
5+
6+
o "github.com/onsi/gomega"
7+
8+
exutil "github.com/openshift/origin/test/extended/util"
9+
e2e "k8s.io/kubernetes/test/e2e/framework"
10+
)
11+
12+
func getCgroupVersion(oc *exutil.CLI) string {
13+
workerNode, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("nodes", "-l", "node-role.kubernetes.io/worker", "-o=jsonpath={.items[0].metadata.name}").Output()
14+
o.Expect(err).NotTo(o.HaveOccurred())
15+
cgroupVersion, err := oc.AsAdmin().WithoutNamespace().Run("debug").Args("node/"+workerNode, "-ndefault", "--", "chroot", "/host", "/bin/bash", "-c", "stat -c %T -f /sys/fs/cgroup").Output()
16+
o.Expect(err).NotTo(o.HaveOccurred())
17+
e2e.Logf("cgroup version info is: [%v]\n", cgroupVersion)
18+
if strings.Contains(cgroupVersion, "tmpfs") {
19+
return "tmpfs"
20+
} else if strings.Contains(cgroupVersion, "cgroup2fs") {
21+
return "cgroup2fs"
22+
}
23+
return cgroupVersion
24+
}

0 commit comments

Comments
 (0)