Skip to content

Commit

Permalink
Understand why restarts are happening
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Seetharaman <[email protected]>
  • Loading branch information
tssurya committed Jan 19, 2025
1 parent a92836d commit dbf0056
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion test/extended/networking/network_segmentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,65 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
// By this time we have spent at least 8 seconds doing the above checks
udnPod, err = cs.CoreV1().Pods(udnPod.Namespace).Get(context.Background(), udnPod.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

// Check pod state and events based on restart count
restartCount := udnPod.Status.ContainerStatuses[0].RestartCount
if restartCount > 0 {
// If pod has restarted, check events to understand why
stdout, err := e2ekubectl.RunKubectl(udnPod.Namespace, "logs", udnPod.Name, "-c",
"agnhost-container",
)
fmt.Printf("SURYA %v/ %v", stdout, err)
stdout, err = e2ekubectl.RunKubectl(udnPod.Namespace, "logs", udnPod.Name, "-c",
"agnhost-container", "--previous",
)
fmt.Printf("SURYA %v/ %v", stdout, err)
stdout, err = e2ekubectl.RunKubectl(udnPod.Namespace, "get", udnPod.Name, "-oyaml")
fmt.Printf("SURYA %v/ %v", stdout, err)
Eventually(func() error {
events, err := cs.CoreV1().Events(udnPod.Namespace).List(context.TODO(),
metav1.ListOptions{
FieldSelector: fmt.Sprintf("involvedObject.name=%s", udnPod.Name),
})
if err != nil {
return err
}
if len(events.Items) == 0 {
return fmt.Errorf("no events found for pod with %d restarts", restartCount)
}
// Log all events
for _, event := range events.Items {
fmt.Printf("Pod event: Type=%s Reason=%s Message=%s LastTimestamp=%v Count=%d\n",
event.Type, event.Reason, event.Message, event.LastTimestamp, event.Count)
}
return nil
}, "30s", "1s").Should(Succeed())
} else {
// If no restarts, still print all events for debugging
Eventually(func() error {
events, err := cs.CoreV1().Events(udnPod.Namespace).List(context.TODO(),
metav1.ListOptions{
FieldSelector: fmt.Sprintf("involvedObject.name=%s", udnPod.Name),
})
if err != nil {
return err
}
if len(events.Items) == 0 {
fmt.Printf("no events found for pod")
}
fmt.Printf("Pod events with no restarts:\n")
for _, event := range events.Items {
fmt.Printf("Pod event: Type=%s Reason=%s Message=%s LastTimestamp=%v Count=%d\n",
event.Type, event.Reason, event.Message, event.LastTimestamp, event.Count)
}
return nil
}, "30s", "1s").Should(Succeed())
}
Expect(udnPod.Status.ContainerStatuses[0].RestartCount).To(Equal(int32(0)))

By("asserting healthcheck works (kubelet can access the UDN pod)")
// The pod should be ready
Expect(podutils.IsPodReady(udnPod)).To(BeTrue())
Expect(podutils.IsPodReady(udnPod)).To(BeTrue(), fmt.Sprintf("UDN pod is not ready: %v", udnPod))

// TODO
//By("checking non-kubelet default network host process can't reach the UDN pod")
Expand Down

0 comments on commit dbf0056

Please sign in to comment.