From 26f572e3303663701e2ed4a74644490aa5eb9450 Mon Sep 17 00:00:00 2001 From: Mikhail Abramov Date: Fri, 20 Jun 2025 13:03:43 +0200 Subject: [PATCH] Stabilize e2e dual-stack test Signed-off-by: Mikhail Abramov --- tests/e2e/ambient/ambient_test.go | 13 ++++---- tests/e2e/controlplane/control_plane_test.go | 15 ++------- .../controlplane/control_plane_update_test.go | 11 ++----- tests/e2e/dualstack/dualstack_test.go | 17 ++++------ tests/e2e/util/common/e2e_utils.go | 32 +++++++++++-------- 5 files changed, 35 insertions(+), 53 deletions(-) diff --git a/tests/e2e/ambient/ambient_test.go b/tests/e2e/ambient/ambient_test.go index 3365d72a5..092dd5f41 100644 --- a/tests/e2e/ambient/ambient_test.go +++ b/tests/e2e/ambient/ambient_test.go @@ -34,6 +34,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( @@ -256,19 +257,17 @@ spec: Expect(k.Label("namespace", common.HttpbinNamespace, "istio.io/dataplane-mode", "ambient")).To(Succeed(), "Error labeling httpbin namespace") // Deploy the test pods. - Expect(k.WithNamespace(common.SleepNamespace).Apply(common.GetSampleYAML(version, "sleep"))).To(Succeed(), "error deploying sleep pod") - Expect(k.WithNamespace(common.HttpbinNamespace).Apply(common.GetSampleYAML(version, "httpbin"))).To(Succeed(), "error deploying httpbin pod") + Expect(k.WithNamespace(common.SleepNamespace).Apply(common.GetSampleYAML(version, "sleep"))).To(Succeed(), "Error deploying sleep pod") + Expect(k.WithNamespace(common.HttpbinNamespace).Apply(common.GetSampleYAML(version, "httpbin"))).To(Succeed(), "Error deploying httpbin pod") Success("Ambient validation pods deployed") }) sleepPod := &corev1.PodList{} It("updates the status of pods to Running", func(ctx SpecContext) { - sleepPod, err = common.CheckPodsReady(ctx, cl, common.SleepNamespace) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error checking status of sleep pod: %v", err)) - - _, err = common.CheckPodsReady(ctx, cl, common.HttpbinNamespace) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error checking status of httpbin pod: %v", err)) + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, common.SleepNamespace).Should(Succeed(), "Error checking status of sleep pod") + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, common.HttpbinNamespace).Should(Succeed(), "Error checking status of httpbin pod") + Expect(cl.List(ctx, sleepPod, client.InNamespace(common.SleepNamespace))).To(Succeed(), "Error getting the pod in sleep namespace") Success("Pods are ready") }) diff --git a/tests/e2e/controlplane/control_plane_test.go b/tests/e2e/controlplane/control_plane_test.go index 96e158ec5..e540a90bb 100644 --- a/tests/e2e/controlplane/control_plane_test.go +++ b/tests/e2e/controlplane/control_plane_test.go @@ -215,21 +215,10 @@ spec: }) samplePods := &corev1.PodList{} - It("updates the pods status to Running", func(ctx SpecContext) { - Eventually(func() bool { - // Wait until the sample pod exists. Is wraped inside a function to avoid failure on the first iteration - Expect(cl.List(ctx, samplePods, client.InNamespace(sampleNamespace))).To(Succeed()) - return len(samplePods.Items) > 0 - }).Should(BeTrue(), "No sample pods found") - - Expect(cl.List(ctx, samplePods, client.InNamespace(sampleNamespace))).To(Succeed()) - Expect(samplePods.Items).ToNot(BeEmpty(), "No pods found in sample namespace") + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, sampleNamespace).Should(Succeed(), "Error checking status of sample pods") + Expect(cl.List(ctx, samplePods, client.InNamespace(sampleNamespace))).To(Succeed(), "Error getting the pods in sample namespace") - for _, pod := range samplePods.Items { - Eventually(common.GetObject).WithArguments(ctx, cl, kube.Key(pod.Name, sampleNamespace), &corev1.Pod{}). - Should(HaveConditionStatus(corev1.PodReady, metav1.ConditionTrue), "Pod is not Ready") - } Success("sample pods are ready") }) diff --git a/tests/e2e/controlplane/control_plane_update_test.go b/tests/e2e/controlplane/control_plane_update_test.go index 3d09b9c87..67dc4d334 100644 --- a/tests/e2e/controlplane/control_plane_update_test.go +++ b/tests/e2e/controlplane/control_plane_update_test.go @@ -146,16 +146,9 @@ spec: Success("sample deployed") samplePods := &corev1.PodList{} + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, sampleNamespace).Should(Succeed(), "Error checking status of sample pods") + Expect(cl.List(ctx, samplePods, client.InNamespace(sampleNamespace))).To(Succeed(), "Error getting the pods in sample namespace") - Eventually(func() bool { - Expect(cl.List(ctx, samplePods, client.InNamespace(sampleNamespace))).To(Succeed()) - return len(samplePods.Items) > 0 - }).Should(BeTrue(), "No sample pods found") - - for _, pod := range samplePods.Items { - Eventually(common.GetObject).WithArguments(ctx, cl, kube.Key(pod.Name, sampleNamespace), &corev1.Pod{}). - Should(HaveConditionStatus(corev1.PodReady, metav1.ConditionTrue), "Pod is not Ready") - } Success("sample pods are ready") for _, pod := range samplePods.Items { diff --git a/tests/e2e/dualstack/dualstack_test.go b/tests/e2e/dualstack/dualstack_test.go index 1b2124d8b..db9b413b4 100644 --- a/tests/e2e/dualstack/dualstack_test.go +++ b/tests/e2e/dualstack/dualstack_test.go @@ -34,6 +34,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( @@ -207,17 +208,11 @@ spec: sleepPod := &corev1.PodList{} It("updates the status of pods to Running", func(ctx SpecContext) { - _, err = common.CheckPodsReady(ctx, cl, DualStackNamespace) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error checking status of dual-stack pods: %v", err)) - - _, err = common.CheckPodsReady(ctx, cl, IPv4Namespace) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error checking status of ipv4 pods: %v", err)) - - _, err = common.CheckPodsReady(ctx, cl, IPv6Namespace) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error checking status of ipv6 pods: %v", err)) - - sleepPod, err = common.CheckPodsReady(ctx, cl, SleepNamespace) - Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Error checking status of sleep pods: %v", err)) + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, DualStackNamespace).Should(Succeed(), "Error checking status of dual-stack pod") + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, IPv4Namespace).Should(Succeed(), "Error checking status of ipv4 pod") + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, IPv6Namespace).Should(Succeed(), "Error checking status of ipv6 pod") + Eventually(common.CheckPodsReady).WithArguments(ctx, cl, SleepNamespace).Should(Succeed(), "Error checking status of sleep pod") + Expect(cl.List(ctx, sleepPod, client.InNamespace(SleepNamespace))).To(Succeed(), "Error getting the pod in sleep namespace") Success("Pods are ready") }) diff --git a/tests/e2e/util/common/e2e_utils.go b/tests/e2e/util/common/e2e_utils.go index 2690f6c81..9649ab8ff 100644 --- a/tests/e2e/util/common/e2e_utils.go +++ b/tests/e2e/util/common/e2e_utils.go @@ -29,9 +29,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/istio-ecosystem/sail-operator/pkg/env" "github.com/istio-ecosystem/sail-operator/pkg/istioversion" - "github.com/istio-ecosystem/sail-operator/pkg/kube" "github.com/istio-ecosystem/sail-operator/pkg/test/project" - . "github.com/istio-ecosystem/sail-operator/tests/e2e/util/gomega" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/helm" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/istioctl" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl" @@ -39,7 +37,6 @@ import ( . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" "istio.io/istio/pkg/ptr" @@ -291,22 +288,31 @@ func GetVersionFromIstiod() (*semver.Version, error) { return nil, fmt.Errorf("error getting version from istiod: version not found in output: %s", output) } -func CheckPodsReady(ctx SpecContext, cl client.Client, namespace string) (*corev1.PodList, error) { - podList := &corev1.PodList{} - - err := cl.List(ctx, podList, client.InNamespace(namespace)) - if err != nil { - return nil, fmt.Errorf("failed to list pods in %s namespace: %w", namespace, err) +func isPodReady(pod *corev1.Pod) bool { + for _, cond := range pod.Status.Conditions { + if cond.Type == corev1.PodReady && cond.Status == corev1.ConditionTrue { + return true + } } + return false +} - Expect(podList.Items).ToNot(BeEmpty(), fmt.Sprintf("No pods found in %s namespace", namespace)) +func CheckPodsReady(ctx context.Context, cl client.Client, namespace string) error { + podList := &corev1.PodList{} + if err := cl.List(ctx, podList, client.InNamespace(namespace)); err != nil { + return fmt.Errorf("Failed to list pods: %w", err) + } + if len(podList.Items) == 0 { + return fmt.Errorf("No pods found in namespace %q", namespace) + } for _, pod := range podList.Items { - Eventually(GetObject).WithArguments(ctx, cl, kube.Key(pod.Name, namespace), &corev1.Pod{}). - Should(HaveConditionStatus(corev1.PodReady, metav1.ConditionTrue), fmt.Sprintf("%q Pod in %q namespace is not Ready", pod.Name, namespace)) + if !isPodReady(&pod) { + return fmt.Errorf("pod %q in namespace %q is not ready", pod.Name, namespace) + } } - return podList, nil + return nil } func InstallOperatorViaHelm(extraArgs ...string) error {