|
| 1 | +package node |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "time" |
| 6 | + |
| 7 | + g "github.com/onsi/ginkgo/v2" |
| 8 | + o "github.com/onsi/gomega" |
| 9 | + corev1 "k8s.io/api/core/v1" |
| 10 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 11 | + "k8s.io/kubernetes/test/e2e/framework" |
| 12 | + e2epod "k8s.io/kubernetes/test/e2e/framework/pod" |
| 13 | + |
| 14 | + configv1 "github.com/openshift/api/config/v1" |
| 15 | + mcclient "github.com/openshift/client-go/machineconfiguration/clientset/versioned" |
| 16 | + exutil "github.com/openshift/origin/test/extended/util" |
| 17 | + "github.com/openshift/origin/test/extended/util/image" |
| 18 | +) |
| 19 | + |
| 20 | +// runc Deprecation Test Suite |
| 21 | + |
| 22 | +var _ = g.Describe("[Jira:Node][sig-node] runc deprecation cases", func() { |
| 23 | + defer g.GinkgoRecover() |
| 24 | + |
| 25 | + var oc = exutil.NewCLI("runc-deprecation") |
| 26 | + |
| 27 | + g.BeforeEach(func(ctx context.Context) { |
| 28 | + isMicroShift, err := exutil.IsMicroShiftCluster(oc.AdminKubeClient()) |
| 29 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to check if cluster is MicroShift") |
| 30 | + if isMicroShift { |
| 31 | + g.Skip("Skipping runc deprecation tests on MicroShift") |
| 32 | + } |
| 33 | + |
| 34 | + controlPlaneTopology, err := exutil.GetControlPlaneTopology(oc) |
| 35 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to get control plane topology") |
| 36 | + if *controlPlaneTopology == configv1.ExternalTopologyMode { |
| 37 | + g.Skip("Skipping runc deprecation tests on Hypershift — MachineConfig API unavailable") |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + // A cluster on RHCOS 9 should use crun as the default container runtime |
| 42 | + // with no custom ContainerRuntimeConfig present. |
| 43 | + g.It("RHCOS 9 cluster install should use crun as the default container runtime", func(ctx context.Context) { |
| 44 | + |
| 45 | + g.By("Checking ClusterVersion is Available and not Progressing") |
| 46 | + cv, err := oc.AdminConfigClient().ConfigV1().ClusterVersions().Get(ctx, "version", metav1.GetOptions{}) |
| 47 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to get ClusterVersion") |
| 48 | + var cvAvailable, cvProgressing bool |
| 49 | + for _, cond := range cv.Status.Conditions { |
| 50 | + switch cond.Type { |
| 51 | + case configv1.OperatorAvailable: |
| 52 | + cvAvailable = cond.Status == configv1.ConditionTrue |
| 53 | + case configv1.OperatorProgressing: |
| 54 | + cvProgressing = cond.Status == configv1.ConditionTrue |
| 55 | + } |
| 56 | + } |
| 57 | + o.Expect(cvAvailable).To(o.BeTrue(), "ClusterVersion should be Available") |
| 58 | + o.Expect(cvProgressing).To(o.BeFalse(), "ClusterVersion should not be Progressing") |
| 59 | + framework.Logf("ClusterVersion %s: Available=%v Progressing=%v", |
| 60 | + cv.Status.Desired.Version, cvAvailable, cvProgressing) |
| 61 | + |
| 62 | + g.By("Getting a worker node for inspection") |
| 63 | + workerNodes, err := getNodesByLabel(ctx, oc, "node-role.kubernetes.io/worker") |
| 64 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to list worker nodes") |
| 65 | + o.Expect(workerNodes).NotTo(o.BeEmpty(), "expected at least one worker node") |
| 66 | + targetNode := workerNodes[0].Name |
| 67 | + framework.Logf("Using worker node: %s", targetNode) |
| 68 | + |
| 69 | + g.By("Checking RHCOS 9 is reported in /etc/os-release on the worker node") |
| 70 | + osRelease, err := ExecOnNodeWithChroot(oc, targetNode, "cat", "/etc/os-release") |
| 71 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to read /etc/os-release on node %s", targetNode) |
| 72 | + o.Expect(osRelease).To(o.ContainSubstring("VARIANT_ID=coreos"), |
| 73 | + "expected RHCOS (VARIANT_ID=coreos) on node %s", targetNode) |
| 74 | + o.Expect(osRelease).To(o.ContainSubstring(`VERSION_ID="9.`), |
| 75 | + "expected RHCOS 9 (VERSION_ID=\"9.x\") on node %s", targetNode) |
| 76 | + framework.Logf("Confirmed: node %s is running RHCOS 9", targetNode) |
| 77 | + |
| 78 | + g.By("Checking no ContainerRuntimeConfig resources exist") |
| 79 | + mcClient, err := mcclient.NewForConfig(oc.KubeFramework().ClientConfig()) |
| 80 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to create MachineConfig client") |
| 81 | + ctrcfgList, err := mcClient.MachineconfigurationV1().ContainerRuntimeConfigs().List(ctx, metav1.ListOptions{}) |
| 82 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to list ContainerRuntimeConfigs") |
| 83 | + o.Expect(ctrcfgList.Items).To(o.BeEmpty(), |
| 84 | + "expected no ContainerRuntimeConfigs on a fresh cluster, found %d item(s)", len(ctrcfgList.Items)) |
| 85 | + framework.Logf("Confirmed: no custom ContainerRuntimeConfig exists") |
| 86 | + |
| 87 | + g.By("Checking CRI-O default_runtime is crun on the worker node") |
| 88 | + crioConfig, err := ExecOnNodeWithChroot(oc, targetNode, "crio", "status", "config") |
| 89 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to get CRI-O status config on node %s", targetNode) |
| 90 | + o.Expect(crioConfig).To(o.ContainSubstring(`default_runtime = "crun"`), |
| 91 | + "expected CRI-O default_runtime to be crun on node %s", targetNode) |
| 92 | + framework.Logf("Confirmed: CRI-O default_runtime is crun on node %s", targetNode) |
| 93 | + |
| 94 | + g.By("Checking machine-config ClusterOperator is Available and not Degraded") |
| 95 | + co, err := oc.AdminConfigClient().ConfigV1().ClusterOperators().Get(ctx, "machine-config", metav1.GetOptions{}) |
| 96 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to get machine-config ClusterOperator") |
| 97 | + var mcAvailable, mcProgressing, mcDegraded bool |
| 98 | + for _, cond := range co.Status.Conditions { |
| 99 | + switch cond.Type { |
| 100 | + case configv1.OperatorAvailable: |
| 101 | + mcAvailable = cond.Status == configv1.ConditionTrue |
| 102 | + case configv1.OperatorProgressing: |
| 103 | + mcProgressing = cond.Status == configv1.ConditionTrue |
| 104 | + case configv1.OperatorDegraded: |
| 105 | + mcDegraded = cond.Status == configv1.ConditionTrue |
| 106 | + } |
| 107 | + } |
| 108 | + o.Expect(mcAvailable).To(o.BeTrue(), "machine-config ClusterOperator should be Available") |
| 109 | + o.Expect(mcProgressing).To(o.BeFalse(), "machine-config ClusterOperator should not be Progressing") |
| 110 | + o.Expect(mcDegraded).To(o.BeFalse(), "machine-config ClusterOperator should not be Degraded") |
| 111 | + framework.Logf("Confirmed: machine-config ClusterOperator is healthy (Available=true Progressing=false Degraded=false)") |
| 112 | + |
| 113 | + g.By("Creating a test pod with ubi9-minimal image") |
| 114 | + namespace := oc.Namespace() |
| 115 | + pod := &corev1.Pod{ |
| 116 | + ObjectMeta: metav1.ObjectMeta{ |
| 117 | + Name: "test-fresh-crun", |
| 118 | + Namespace: namespace, |
| 119 | + }, |
| 120 | + Spec: corev1.PodSpec{ |
| 121 | + NodeSelector: map[string]string{ |
| 122 | + "kubernetes.io/hostname": targetNode, |
| 123 | + }, |
| 124 | + RestartPolicy: corev1.RestartPolicyNever, |
| 125 | + Containers: []corev1.Container{ |
| 126 | + { |
| 127 | + Name: "ubi-minimal", |
| 128 | + Image: image.LocationFor("registry.access.redhat.com/ubi9/ubi-minimal"), |
| 129 | + Command: []string{"echo", "crun-fresh-install-test-passed"}, |
| 130 | + }, |
| 131 | + }, |
| 132 | + }, |
| 133 | + } |
| 134 | + _, err = oc.KubeClient().CoreV1().Pods(namespace).Create(ctx, pod, metav1.CreateOptions{}) |
| 135 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to create test pod") |
| 136 | + |
| 137 | + g.By("Waiting for the test pod to reach Succeeded phase") |
| 138 | + err = e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, oc.KubeClient(), pod.Name, namespace, 2*time.Minute) |
| 139 | + o.Expect(err).NotTo(o.HaveOccurred(), "test pod did not complete successfully with crun runtime") |
| 140 | + |
| 141 | + resultPod, err := oc.KubeClient().CoreV1().Pods(namespace).Get(ctx, pod.Name, metav1.GetOptions{}) |
| 142 | + o.Expect(err).NotTo(o.HaveOccurred(), "failed to get test pod after completion") |
| 143 | + o.Expect(resultPod.Status.Phase).To(o.Equal(corev1.PodSucceeded), |
| 144 | + "test pod should have Succeeded, got phase: %s", resultPod.Status.Phase) |
| 145 | + framework.Logf("Test PASSED: RHCOS 9 cluster uses crun as default runtime and workloads run successfully") |
| 146 | + }) |
| 147 | +}) |
0 commit comments