From 3d318b57e301e07747d7ba3a94ff4c57af7142ea Mon Sep 17 00:00:00 2001 From: zylxjtu Date: Fri, 28 Feb 2025 19:39:21 +0000 Subject: [PATCH] revert the old loop to check if the node is rebooted --- test/e2e/windows/reboot_node.go | 49 +++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/test/e2e/windows/reboot_node.go b/test/e2e/windows/reboot_node.go index 3114992f957..827c213a09e 100644 --- a/test/e2e/windows/reboot_node.go +++ b/test/e2e/windows/reboot_node.go @@ -53,6 +53,8 @@ var _ = sigDescribe(feature.Windows, "[Excluded:WindowsDocker] [MinimumKubeletVe bootID, err := strconv.Atoi(targetNode.Status.NodeInfo.BootID) framework.ExpectNoError(err, "Error converting bootID to int") + framework.Logf("Initial BootID: %d", bootID) + windowsImage := imageutils.GetE2EImage(imageutils.Agnhost) // Create Windows pod on the selected Windows node Using Agnhost @@ -179,29 +181,40 @@ var _ = sigDescribe(feature.Windows, "[Excluded:WindowsDocker] [MinimumKubeletVe restartCount := 0 - ginkgo.By("Waiting for nodes to be rebooted") - gomega.Eventually(ctx, func(ctx context.Context) int { - refreshNode, err := f.ClientSet.CoreV1().Nodes().Get(ctx, targetNode.Name, metav1.GetOptions{}) - if err != nil { - return -1 + timeout := time.After(time.Minute * 10) + FOR: + for { + select { + case <-timeout: + break FOR + default: + if restartCount > 0 { + break FOR + } + ginkgo.By("Then checking existed agn-test-pod is running on the rebooted host") + agnPodOut, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, agnPod.Name, metav1.GetOptions{}) + if err == nil { + lastRestartCount := podutil.GetExistingContainerStatus(agnPodOut.Status.ContainerStatuses, "windows-container").RestartCount + restartCount = int(lastRestartCount - initialRestartCount) + } + time.Sleep(time.Second * 30) } - num, err := strconv.Atoi(refreshNode.Status.NodeInfo.BootID) // Attempt to convert empty string - if err != nil { - return -1 // strconv.Atoi: parsing "": invalid syntax - } else { - return num - } - }).WithPolling(time.Second*30).WithTimeout(time.Minute*10). - Should(gomega.BeNumerically(">", bootID), "node was not rebooted") + } - ginkgo.By("Then checking existed agn-test-pod is running on the rebooted host") - agnPodOut, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, agnPod.Name, metav1.GetOptions{}) - framework.ExpectNoError(err, "getting pod info after reboot") + ginkgo.By("Checking whether the node is rebooted") + refreshNode, err := f.ClientSet.CoreV1().Nodes().Get(ctx, targetNode.Name, metav1.GetOptions{}) + framework.ExpectNoError(err, "Error getting node info after reboot") + currentbootID, err := strconv.Atoi(refreshNode.Status.NodeInfo.BootID) + framework.ExpectNoError(err, "Error converting bootID to int") + framework.Logf("current BootID: %d", currentbootID) + gomega.Expect(currentbootID).To(gomega.Equal(bootID+1), "BootID should be incremented by 1 after reboot") - lastRestartCount := podutil.GetExistingContainerStatus(agnPodOut.Status.ContainerStatuses, "windows-container").RestartCount - restartCount = int(lastRestartCount - initialRestartCount) + ginkgo.By("Checking whether agn-test-pod is rebooted") gomega.Expect(restartCount).To(gomega.Equal(1), "restart count of agn-test-pod is 1") + + agnPodOut, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, agnPod.Name, metav1.GetOptions{}) gomega.Expect(agnPodOut.Status.Phase).To(gomega.Equal(v1.PodRunning)) + framework.ExpectNoError(err, "getting pod info after reboot") assertConsistentConnectivity(ctx, f, nginxPod.ObjectMeta.Name, "linux", linuxCheck(agnPodOut.Status.PodIP, 80), internalMaxTries) // create another host process pod to check system boot time