Skip to content

Commit ba71449

Browse files
authored
Merge pull request kubernetes#130329 from zylxjtu/bootid
Fix the node reboot validation failure
2 parents a5dda5d + 3d318b5 commit ba71449

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

test/e2e/windows/reboot_node.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package windows
1818

1919
import (
2020
"context"
21+
"strconv"
2122
"time"
2223

2324
"github.com/onsi/ginkgo/v2"
@@ -50,7 +51,10 @@ var _ = sigDescribe(feature.Windows, "[Excluded:WindowsDocker] [MinimumKubeletVe
5051
framework.ExpectNoError(err, "Error finding Windows node")
5152
framework.Logf("Using node: %v", targetNode.Name)
5253

53-
bootID := targetNode.Status.NodeInfo.BootID
54+
bootID, err := strconv.Atoi(targetNode.Status.NodeInfo.BootID)
55+
framework.ExpectNoError(err, "Error converting bootID to int")
56+
framework.Logf("Initial BootID: %d", bootID)
57+
5458
windowsImage := imageutils.GetE2EImage(imageutils.Agnhost)
5559

5660
// Create Windows pod on the selected Windows node Using Agnhost
@@ -177,24 +181,40 @@ var _ = sigDescribe(feature.Windows, "[Excluded:WindowsDocker] [MinimumKubeletVe
177181

178182
restartCount := 0
179183

180-
ginkgo.By("Waiting for nodes to be rebooted")
181-
gomega.Eventually(ctx, func(ctx context.Context) string {
182-
refreshNode, err := f.ClientSet.CoreV1().Nodes().Get(ctx, targetNode.Name, metav1.GetOptions{})
183-
if err != nil {
184-
return ""
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)
185201
}
186-
return refreshNode.Status.NodeInfo.BootID
187-
}).WithPolling(time.Second*30).WithTimeout(time.Minute*10).
188-
Should(gomega.BeNumerically(">", bootID), "node was not rebooted")
202+
}
189203

190-
ginkgo.By("Then checking existed agn-test-pod is running on the rebooted host")
191-
agnPodOut, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, agnPod.Name, metav1.GetOptions{})
192-
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")
193211

194-
lastRestartCount := podutil.GetExistingContainerStatus(agnPodOut.Status.ContainerStatuses, "windows-container").RestartCount
195-
restartCount = int(lastRestartCount - initialRestartCount)
212+
ginkgo.By("Checking whether agn-test-pod is rebooted")
196213
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{})
197216
gomega.Expect(agnPodOut.Status.Phase).To(gomega.Equal(v1.PodRunning))
217+
framework.ExpectNoError(err, "getting pod info after reboot")
198218
assertConsistentConnectivity(ctx, f, nginxPod.ObjectMeta.Name, "linux", linuxCheck(agnPodOut.Status.PodIP, 80), internalMaxTries)
199219

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

0 commit comments

Comments
 (0)