Skip to content

Commit

Permalink
E2E: make sure frr-k8s-webhook pod is Ready
Browse files Browse the repository at this point in the history
Frr-k8s-webhook is crashes at least 3 times and then it becomes ready,
but sometimes it remains crashing.

Current check is checking if pod is Running but this is not enough
```
   containerStatuses:
    - containerID: containerd://fe46fd402ccb0ea512037e4fbc3c12c90de7c7e40ed4adb0ee5c51681f89b8d7
      image: quay.io/metallb/frr-k8s:v0.0.14
      imageID: quay.io/metallb/frr-k8s@sha256:00f8c40129fb1403760d2e846fc970dc11ca8d19068f012a26f2b683f98cb598
      lastState:
        terminated:
          containerID: containerd://22f5f5ccbe3832019b15460f5a6947ce22bba838bc45cbaa6c60b0c0f94b4aaf
          exitCode: 0
          finishedAt: "2024-09-19T08:11:19Z"
          reason: Completed
          startedAt: "2024-09-19T08:11:18Z"
      name: frr-k8s-webhook-server
      ready: false
      restartCount: 1
      started: false
      state:
        terminated:
          containerID: containerd://fe46fd402ccb0ea512037e4fbc3c12c90de7c7e40ed4adb0ee5c51681f89b8d7
          exitCode: 1
          finishedAt: "2024-09-19T08:11:21Z"
          reason: Error
          startedAt: "2024-09-19T08:11:20Z"
    hostIP: 172.18.0.3
    hostIPs:
    - ip: 172.18.0.3
    phase: Running
```

```
 k -n metallb-system get pods -l  component=frr-k8s-webhook-server -o wide -w
NAME                                      READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Pending   0          0s    <none>   <none>   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Pending   0          0s    <none>   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     ContainerCreating   0          0s    <none>   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Running             0          0s    10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Completed           0          1s    10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Running             1 (2s ago)   3s    10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Error               1 (4s ago)   5s    10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     CrashLoopBackOff    1 (7s ago)   10s   10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Running             2 (23s ago)   26s   10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Completed           2 (24s ago)   27s   10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     CrashLoopBackOff    2 (2s ago)    28s   10.244.2.11   kind-worker   <none>           <none>

frr-k8s-webhook-server-6ffd7bc857-glnvr   0/1     Running             3 (35s ago)   61s   10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   1/1     Running             3 (44s ago)   70s   10.244.2.11   kind-worker   <none>           <none>
frr-k8s-webhook-server-6ffd7bc857-glnvr   1/1     Terminating         3 (76s ago)   102s   10.244.2.11   kind-worker   <none>           <none>
```

Signed-off-by: karampok <[email protected]>
  • Loading branch information
karampok committed Sep 19, 2024
1 parent 7d8418f commit c79cdec
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions test/e2e/functional/tests/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ var _ = Describe("metallb", func() {
}, metallbutils.DeployTimeout, metallbutils.Interval).ShouldNot(HaveOccurred())

By("checking frr-k8s webhook deployment is in running state")
Eventually(func() error {
c := func() error {
deploy, err := testclient.Client.Deployments(metallb.Namespace).Get(context.Background(), consts.FRRK8SWebhookDeploymentName, metav1.GetOptions{})
if err != nil {
return err
Expand All @@ -297,18 +297,21 @@ var _ = Describe("metallb", func() {
}

for _, pod := range pods.Items {
if pod.Status.Phase != corev1.PodRunning {
if !PodIsReady(&pod) {
return fmt.Errorf("deployment %s pod %s is not running, expected status %s got %s", consts.MetalLBOperatorDeploymentName, pod.Name, corev1.PodRunning, pod.Status.Phase)
}
}

return nil
}, metallbutils.DeployTimeout, metallbutils.Interval).ShouldNot(HaveOccurred())
}
Eventually(c, metallbutils.DeployTimeout, metallbutils.Interval).ShouldNot(HaveOccurred())
By("Consistently be running")
Consistently(c, 30*time.Second, metallbutils.Interval).ShouldNot(HaveOccurred())

},
Entry("Native Mode", metallbv1beta1.NativeMode),
Entry("FRR Mode", metallbv1beta1.FRRMode),
Entry("FRR-K8s Mode", metallbv1beta1.FRRK8sMode),
FEntry("FRR-K8s Mode", metallbv1beta1.FRRK8sMode),
)

})
Expand Down Expand Up @@ -799,3 +802,22 @@ var _ = Describe("metallb", func() {
// Gomega transformation functions for v1.Container
func envGetter(c v1.Container) []v1.EnvVar { return c.Env }
func nameGetter(c v1.Container) string { return c.Name }

func PodIsReady(p *corev1.Pod) bool {
return podConditionStatus(p, corev1.PodReady) == corev1.ConditionTrue && podConditionStatus(p, corev1.ContainersReady) == corev1.ConditionTrue
}

// podConditionStatus returns the status of the condition for a given pod.
func podConditionStatus(p *corev1.Pod, condition corev1.PodConditionType) corev1.ConditionStatus {
if p == nil {
return corev1.ConditionUnknown
}

for _, c := range p.Status.Conditions {
if c.Type == condition {
return c.Status
}
}

return corev1.ConditionUnknown
}

0 comments on commit c79cdec

Please sign in to comment.