diff --git a/test/e2e/basic/sysctl_d_override.go b/test/e2e/basic/sysctl_d_override.go index 8bfaa8a6e8..47925cf513 100644 --- a/test/e2e/basic/sysctl_d_override.go +++ b/test/e2e/basic/sysctl_d_override.go @@ -21,15 +21,15 @@ var _ = ginkgo.Describe("[basic][sysctl_d_override] Node Tuning Operator /etc/sy const ( sysctlVar = "net.ipv4.neigh.default.gc_thresh1" sysctlValSet = "256" - sysctlFile = "/host/etc/sysctl.d/zzz.conf" + sysctlFile = "/rootfs/etc/sysctl.d/zzz.conf" profileSysctlOverride = "../testing_manifests/sysctl_override.yaml" nodeLabelSysctlOverride = "tuned.openshift.io/sysctl-override" ) ginkgo.Context("sysctl.d override", func() { var ( - node *coreapi.Node - pod *coreapi.Pod + node *coreapi.Node + pod, mcdPod *coreapi.Pod ) // Cleanup code to roll back cluster changes done by this test even if it fails in the middle of ginkgo.It() @@ -38,7 +38,9 @@ var _ = ginkgo.Describe("[basic][sysctl_d_override] Node Tuning Operator /etc/sy if node != nil { util.ExecAndLogCommand("oc", "label", "node", "--overwrite", node.Name, nodeLabelSysctlOverride+"-") - util.ExecAndLogCommand("oc", "debug", fmt.Sprintf("no/%s", node.Name), "--", "rm", sysctlFile) + } + if mcdPod != nil { + util.ExecAndLogCommand("oc", "exec", "-n", util.MCONamespace, mcdPod.Name, "--", "rm", sysctlFile) } util.ExecAndLogCommand("oc", "delete", "-n", ntoconfig.WatchNamespace(), "-f", profileSysctlOverride) }) @@ -60,6 +62,9 @@ var _ = ginkgo.Describe("[basic][sysctl_d_override] Node Tuning Operator /etc/sy pod, err = util.GetTunedForNode(cs, node) gomega.Expect(err).NotTo(gomega.HaveOccurred()) + mcdPod, err = util.GetMCDForNode(cs, node) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + // Expect the default worker node profile applied prior to getting any current values. ginkgo.By(fmt.Sprintf("waiting for TuneD profile %s on node %s", util.GetDefaultWorkerProfile(node), node.Name)) err = util.WaitForProfileConditionStatus(cs, pollInterval, waitDuration, node.Name, util.GetDefaultWorkerProfile(node), tunedv1.TunedProfileApplied, coreapi.ConditionTrue) @@ -70,11 +75,11 @@ var _ = ginkgo.Describe("[basic][sysctl_d_override] Node Tuning Operator /etc/sy gomega.Expect(err).NotTo(gomega.HaveOccurred()) ginkgo.By(fmt.Sprintf("writing %s override file on the host with %s=%s", sysctlFile, sysctlVar, sysctlValSet)) - _, _, err = util.ExecAndLogCommand("oc", "debug", fmt.Sprintf("no/%s", node.Name), "--", "sh", "-c", + _, _, err = util.ExecAndLogCommand("oc", "exec", "-n", util.MCONamespace, mcdPod.Name, "--", "sh", "-c", fmt.Sprintf("echo %s=%s > %s; sync %s", sysctlVar, sysctlValSet, sysctlFile, sysctlFile)) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - util.ExecAndLogCommand("oc", "rsh", "-n", ntoconfig.WatchNamespace(), pod.Name, "cat", sysctlFile) + util.ExecAndLogCommand("oc", "rsh", "-n", util.MCONamespace, mcdPod.Name, "cat", sysctlFile) ginkgo.By(fmt.Sprintf("deleting Pod %s", pod.Name)) _, _, err = util.ExecAndLogCommand("oc", "delete", "-n", ntoconfig.WatchNamespace(), "pod", pod.Name, "--wait") @@ -116,7 +121,7 @@ var _ = ginkgo.Describe("[basic][sysctl_d_override] Node Tuning Operator /etc/sy gomega.Expect(err).NotTo(gomega.HaveOccurred()) ginkgo.By(fmt.Sprintf("removing %s override file on the host", sysctlFile)) - _, _, err = util.ExecAndLogCommand("oc", "debug", fmt.Sprintf("no/%s", node.Name), "--", "rm", sysctlFile) + _, _, err = util.ExecAndLogCommand("oc", "exec", "-n", util.MCONamespace, mcdPod.Name, "--", "rm", sysctlFile) gomega.Expect(err).NotTo(gomega.HaveOccurred()) ginkgo.By(fmt.Sprintf("deleting Pod %s", pod.Name)) diff --git a/test/e2e/util/util.go b/test/e2e/util/util.go index cf366d09b0..015f66e286 100644 --- a/test/e2e/util/util.go +++ b/test/e2e/util/util.go @@ -29,6 +29,8 @@ const ( DefaultMasterProfile = "openshift-control-plane" // The default worker profile. See: assets/tuned/manifests/default-cr-tuned.yaml DefaultWorkerProfile = "openshift-node" + // MCO namespace + MCONamespace = "openshift-machine-config-operator" ) // Logf formats using the default formats for its operands and writes to @@ -80,6 +82,26 @@ func GetTunedForNode(cs *framework.ClientSet, node *corev1.Node) (*corev1.Pod, e return &podList.Items[0], nil } +// GetMCDForNode returns a MCD Pod that runs on a given node. +func GetMCDForNode(cs *framework.ClientSet, node *corev1.Node) (*corev1.Pod, error) { + listOptions := metav1.ListOptions{ + FieldSelector: fields.SelectorFromSet(fields.Set{"spec.nodeName": node.Name}).String(), + } + listOptions.LabelSelector = labels.SelectorFromSet(labels.Set{"k8s-app": "machine-config-daemon"}).String() + + podList, err := cs.Pods(MCONamespace).List(context.TODO(), listOptions) + if err != nil { + return nil, err + } + if len(podList.Items) != 1 { + if len(podList.Items) == 0 { + return nil, fmt.Errorf("failed to find MCD for node %s", node.Name) + } + return nil, fmt.Errorf("too many (%d) MCD Pods for node %s", len(podList.Items), node.Name) + } + return &podList.Items[0], nil +} + // GetNodeTuningOperator returns the node tuning operator Pod. // If more than one operator Pod is running will return the first Pod found. func GetNodeTuningOperatorPod(cs *framework.ClientSet) (*corev1.Pod, error) {