From ddd8b86e7bc0c932b9893dd88f0e9096cbd554fb Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Mon, 28 Oct 2024 11:09:49 +0100 Subject: [PATCH] test: Skip looking for unschedulable pods when running with envtest. We have seen flakiness due to the pods being deleted so fast after manually marking them unschedulable, that the ListPods never gets to see the unschedulable pods. --- .../clusters/humiocluster_controller_test.go | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/controllers/suite/clusters/humiocluster_controller_test.go b/controllers/suite/clusters/humiocluster_controller_test.go index 0ab46dab..37ba30b1 100644 --- a/controllers/suite/clusters/humiocluster_controller_test.go +++ b/controllers/suite/clusters/humiocluster_controller_test.go @@ -354,22 +354,24 @@ var _ = Describe("HumioCluster Controller", func() { ensurePodsGoPending(ctx, controllers.NewHumioNodeManagerFromHumioCluster(&updatedHumioCluster), 2, 1) - Eventually(func() int { - var pendingPodsCount int - updatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, controllers.NewHumioNodeManagerFromHumioCluster(&updatedHumioCluster).GetPodLabels()) - for _, pod := range updatedClusterPods { - if pod.Status.Phase == corev1.PodPending { - for _, condition := range pod.Status.Conditions { - if condition.Type == corev1.PodScheduled { - if condition.Status == corev1.ConditionFalse && condition.Reason == controllers.PodConditionReasonUnschedulable { - pendingPodsCount++ + if !helpers.UseEnvtest() { + Eventually(func() int { + var pendingPodsCount int + updatedClusterPods, _ = kubernetes.ListPods(ctx, k8sClient, updatedHumioCluster.Namespace, controllers.NewHumioNodeManagerFromHumioCluster(&updatedHumioCluster).GetPodLabels()) + for _, pod := range updatedClusterPods { + if pod.Status.Phase == corev1.PodPending { + for _, condition := range pod.Status.Conditions { + if condition.Type == corev1.PodScheduled { + if condition.Status == corev1.ConditionFalse && condition.Reason == controllers.PodConditionReasonUnschedulable { + pendingPodsCount++ + } } } } } - } - return pendingPodsCount - }, testTimeout, 250*time.Millisecond).Should(Equal(1)) + return pendingPodsCount + }, testTimeout, 250*time.Millisecond).Should(Equal(1)) + } suite.UsingClusterBy(key.Name, "Updating the cluster resources successfully with working affinity") Eventually(func() error {