|
| 1 | +package apiserver |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + g "github.com/onsi/ginkgo/v2" |
| 7 | + o "github.com/onsi/gomega" |
| 8 | + |
| 9 | + exutil "github.com/openshift/origin/test/extended/util" |
| 10 | + e2e "k8s.io/kubernetes/test/e2e/framework" |
| 11 | + admissionapi "k8s.io/pod-security-admission/api" |
| 12 | +) |
| 13 | + |
| 14 | +var _ = g.Describe("[sig-api-machinery][E2E-QE-APIServer", func() { |
| 15 | + defer g.GinkgoRecover() |
| 16 | + ctx := context.Background() |
| 17 | + oc := exutil.NewCLIWithPodSecurityLevel("e2e-qe-apiserver", admissionapi.LevelPrivileged) |
| 18 | + |
| 19 | + |
| 20 | + g.It("Init container setup should have the proper securityContext-[OCP-32383]-bug 1793694", func() { |
| 21 | + // Skip on Microshift clusters |
| 22 | + isMicroShift, err := exutil.IsMicroShiftCluster(oc.AdminKubeClient()) |
| 23 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 24 | + if isMicroShift { |
| 25 | + g.Skip("MicroShift has different security context requirements and architecture") |
| 26 | + } |
| 27 | + |
| 28 | + isHyperShift, err := exutil.IsHypershift(ctx, oc.AdminConfigClient()) |
| 29 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 30 | + if isHyperShift { |
| 31 | + g.Skip("HyperShift does not support this test") |
| 32 | + } |
| 33 | + checkItems := []struct { |
| 34 | + namespace string |
| 35 | + container string |
| 36 | + }{ |
| 37 | + { |
| 38 | + namespace: "openshift-kube-apiserver", |
| 39 | + container: "kube-apiserver", |
| 40 | + }, |
| 41 | + { |
| 42 | + namespace: "openshift-apiserver", |
| 43 | + container: "openshift-apiserver", |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | + for _, checkItem := range checkItems { |
| 48 | + g.By("Get one pod name of " + checkItem.namespace) |
| 49 | + e2e.Logf("namespace is :%s", checkItem.namespace) |
| 50 | + podName, err := oc.AsAdmin().Run("get").Args("-n", checkItem.namespace, "pods", "-l apiserver", "-o=jsonpath={.items[0].metadata.name}").Output() |
| 51 | + if err != nil { |
| 52 | + e2e.Failf("Failed to get kube-apiserver pod name and returned error: %v", err) |
| 53 | + } |
| 54 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 55 | + e2e.Logf("Get the kube-apiserver pod name: %s", podName) |
| 56 | + |
| 57 | + g.By("Get privileged value of container " + checkItem.container + " of pod " + podName) |
| 58 | + jsonpath := "-o=jsonpath={range .spec.containers[?(@.name==\"" + checkItem.container + "\")]}{.securityContext.privileged}" |
| 59 | + msg, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("pod", podName, jsonpath, "-n", checkItem.namespace).Output() |
| 60 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 61 | + o.Expect(msg).To(o.ContainSubstring("true")) |
| 62 | + e2e.Logf("#### privileged value: %s ####", msg) |
| 63 | + |
| 64 | + g.By("Get privileged value of initcontainer of pod " + podName) |
| 65 | + jsonpath = "-o=jsonpath={.spec.initContainers[].securityContext.privileged}" |
| 66 | + msg, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("pod", podName, jsonpath, "-n", checkItem.namespace).Output() |
| 67 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 68 | + o.Expect(msg).To(o.ContainSubstring("true")) |
| 69 | + e2e.Logf("#### privileged value: %s ####", msg) |
| 70 | + } |
| 71 | + }) |
| 72 | +}) |
0 commit comments