Skip to content

Commit 3d318b5

Browse files
committed
revert the old loop to check if the node is rebooted
1 parent f161200 commit 3d318b5

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

test/e2e/windows/reboot_node.go

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ var _ = sigDescribe(feature.Windows, "[Excluded:WindowsDocker] [MinimumKubeletVe
5353

5454
bootID, err := strconv.Atoi(targetNode.Status.NodeInfo.BootID)
5555
framework.ExpectNoError(err, "Error converting bootID to int")
56+
framework.Logf("Initial BootID: %d", bootID)
57+
5658
windowsImage := imageutils.GetE2EImage(imageutils.Agnhost)
5759

5860
// Create Windows pod on the selected Windows node Using Agnhost
@@ -179,29 +181,40 @@ var _ = sigDescribe(feature.Windows, "[Excluded:WindowsDocker] [MinimumKubeletVe
179181

180182
restartCount := 0
181183

182-
ginkgo.By("Waiting for nodes to be rebooted")
183-
gomega.Eventually(ctx, func(ctx context.Context) int {
184-
refreshNode, err := f.ClientSet.CoreV1().Nodes().Get(ctx, targetNode.Name, metav1.GetOptions{})
185-
if err != nil {
186-
return -1
187-
}
188-
num, err := strconv.Atoi(refreshNode.Status.NodeInfo.BootID) // Attempt to convert empty string
189-
if err != nil {
190-
return -1 // strconv.Atoi: parsing "": invalid syntax
191-
} else {
192-
return num
184+
timeout := time.After(time.Minute * 10)
185+
FOR:
186+
for {
187+
select {
188+
case <-timeout:
189+
break FOR
190+
default:
191+
if restartCount > 0 {
192+
break FOR
193+
}
194+
ginkgo.By("Then checking existed agn-test-pod is running on the rebooted host")
195+
agnPodOut, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, agnPod.Name, metav1.GetOptions{})
196+
if err == nil {
197+
lastRestartCount := podutil.GetExistingContainerStatus(agnPodOut.Status.ContainerStatuses, "windows-container").RestartCount
198+
restartCount = int(lastRestartCount - initialRestartCount)
199+
}
200+
time.Sleep(time.Second * 30)
193201
}
194-
}).WithPolling(time.Second*30).WithTimeout(time.Minute*10).
195-
Should(gomega.BeNumerically(">", bootID), "node was not rebooted")
202+
}
196203

197-
ginkgo.By("Then checking existed agn-test-pod is running on the rebooted host")
198-
agnPodOut, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, agnPod.Name, metav1.GetOptions{})
199-
framework.ExpectNoError(err, "getting pod info after reboot")
204+
ginkgo.By("Checking whether the node is rebooted")
205+
refreshNode, err := f.ClientSet.CoreV1().Nodes().Get(ctx, targetNode.Name, metav1.GetOptions{})
206+
framework.ExpectNoError(err, "Error getting node info after reboot")
207+
currentbootID, err := strconv.Atoi(refreshNode.Status.NodeInfo.BootID)
208+
framework.ExpectNoError(err, "Error converting bootID to int")
209+
framework.Logf("current BootID: %d", currentbootID)
210+
gomega.Expect(currentbootID).To(gomega.Equal(bootID+1), "BootID should be incremented by 1 after reboot")
200211

201-
lastRestartCount := podutil.GetExistingContainerStatus(agnPodOut.Status.ContainerStatuses, "windows-container").RestartCount
202-
restartCount = int(lastRestartCount - initialRestartCount)
212+
ginkgo.By("Checking whether agn-test-pod is rebooted")
203213
gomega.Expect(restartCount).To(gomega.Equal(1), "restart count of agn-test-pod is 1")
214+
215+
agnPodOut, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, agnPod.Name, metav1.GetOptions{})
204216
gomega.Expect(agnPodOut.Status.Phase).To(gomega.Equal(v1.PodRunning))
217+
framework.ExpectNoError(err, "getting pod info after reboot")
205218
assertConsistentConnectivity(ctx, f, nginxPod.ObjectMeta.Name, "linux", linuxCheck(agnPodOut.Status.PodIP, 80), internalMaxTries)
206219

207220
// create another host process pod to check system boot time

0 commit comments

Comments
 (0)