This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 1798467fd fix(e2e): check succeeded pods instead of running pods
1798467fd is described below

commit 1798467fd5c36011caafc562e8bc5fd1fea77f32
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Fri Aug 15 08:54:47 2025 +0200

    fix(e2e): check succeeded pods instead of running pods
    
    Closes #5912
---
 e2e/common/traits/cron_test.go             | 32 ++++++++++----------
 e2e/common/traits/files/cron-fallback.yaml |  2 ++
 e2e/support/test_support.go                | 48 ++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 16 deletions(-)

diff --git a/e2e/common/traits/cron_test.go b/e2e/common/traits/cron_test.go
index 77b7bd0da..a81d36b10 100644
--- a/e2e/common/traits/cron_test.go
+++ b/e2e/common/traits/cron_test.go
@@ -38,6 +38,18 @@ func TestRunCronExample(t *testing.T) {
        t.Parallel()
        WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
 
+               t.Run("cron-fallback", func(t *testing.T) {
+                       g.Expect(KamelRun(t, ctx, ns, 
"files/cron-fallback.yaml").Execute()).To(Succeed())
+                       g.Eventually(IntegrationCronJob(t, ctx, ns, 
"cron-fallback"), TestTimeoutLong).Should(BeNil())
+                       g.Eventually(IntegrationConditionStatus(t, ctx, ns, 
"cron-fallback", v1.IntegrationConditionReady), TestTimeoutShort).Should(
+                               Equal(corev1.ConditionTrue))
+                       g.Eventually(IntegrationConditionStatus(t, ctx, ns, 
"cron-fallback", v1.IntegrationConditionCronJobAvailable),
+                               
TestTimeoutMedium).Should(Equal(corev1.ConditionFalse))
+                       g.Eventually(IntegrationPodPhase(t, ctx, ns, 
"cron-fallback")).Should(Equal(corev1.PodRunning))
+                       g.Eventually(IntegrationLogs(t, ctx, ns, 
"cron-fallback"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+                       g.Eventually(DeleteIntegrations(t, ctx, 
ns)).Should(Equal(0))
+               })
+
                t.Run("cron-timer", func(t *testing.T) {
                        g.Expect(KamelRun(t, ctx, ns, 
"files/cron-timer.yaml").Execute()).To(Succeed())
                        g.Eventually(IntegrationCronJob(t, ctx, ns, 
"cron-timer"), TestTimeoutLong).ShouldNot(BeNil())
@@ -48,8 +60,8 @@ func TestRunCronExample(t *testing.T) {
                        // As it's a cron, we expect it's triggered, executed 
and turned off
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-timer"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
                        g.Eventually(IntegrationPodPhase(t, ctx, ns, 
"cron-timer")).Should(Equal(corev1.PodRunning))
-                       g.Eventually(IntegrationLogs(t, ctx, ns, 
"cron-timer")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-timer")).Should(Equal(ptr.To(int32(0))))
+                       g.Eventually(LastIntegrationCronLogs(t, ctx, ns, 
"cron-timer")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(DeleteIntegrations(t, ctx, 
ns)).Should(Equal(0))
                })
 
@@ -63,8 +75,8 @@ func TestRunCronExample(t *testing.T) {
                        // As it's a cron, we expect it's triggered, executed 
and turned off
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-java"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
                        g.Eventually(IntegrationPodPhase(t, ctx, ns, 
"cron-java")).Should(Equal(corev1.PodRunning))
-                       g.Eventually(IntegrationLogs(t, ctx, ns, 
"cron-java")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-java")).Should(Equal(ptr.To(int32(0))))
+                       g.Eventually(LastIntegrationCronLogs(t, ctx, ns, 
"cron-java")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(DeleteIntegrations(t, ctx, 
ns)).Should(Equal(0))
                })
 
@@ -78,8 +90,8 @@ func TestRunCronExample(t *testing.T) {
                        // As it's a cron, we expect it's triggered, executed 
and turned off
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-tab"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
                        g.Eventually(IntegrationPodPhase(t, ctx, ns, 
"cron-tab")).Should(Equal(corev1.PodRunning))
-                       g.Eventually(IntegrationLogs(t, ctx, ns, 
"cron-tab")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-tab")).Should(Equal(ptr.To(int32(0))))
+                       g.Eventually(LastIntegrationCronLogs(t, ctx, ns, 
"cron-tab")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(DeleteIntegrations(t, ctx, 
ns)).Should(Equal(0))
                })
 
@@ -93,20 +105,8 @@ func TestRunCronExample(t *testing.T) {
                        // As it's a cron, we expect it's triggered, executed 
and turned off
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-quartz"), TestTimeoutMedium).Should(Equal(ptr.To(int32(1))))
                        g.Eventually(IntegrationPodPhase(t, ctx, ns, 
"cron-quartz")).Should(Equal(corev1.PodRunning))
-                       g.Eventually(IntegrationLogs(t, ctx, ns, 
"cron-quartz")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(IntegrationStatusReplicas(t, ctx, ns, 
"cron-quartz")).Should(Equal(ptr.To(int32(0))))
-                       g.Eventually(DeleteIntegrations(t, ctx, 
ns)).Should(Equal(0))
-               })
-
-               t.Run("cron-fallback", func(t *testing.T) {
-                       g.Expect(KamelRun(t, ctx, ns, 
"files/cron-fallback.yaml").Execute()).To(Succeed())
-                       g.Eventually(IntegrationCronJob(t, ctx, ns, 
"cron-fallback"), TestTimeoutLong).Should(BeNil())
-                       g.Eventually(IntegrationConditionStatus(t, ctx, ns, 
"cron-fallback", v1.IntegrationConditionReady), TestTimeoutShort).Should(
-                               Equal(corev1.ConditionTrue))
-                       g.Eventually(IntegrationConditionStatus(t, ctx, ns, 
"cron-fallback", v1.IntegrationConditionCronJobAvailable),
-                               
TestTimeoutMedium).Should(Equal(corev1.ConditionFalse))
-                       g.Eventually(IntegrationPodPhase(t, ctx, ns, 
"cron-fallback")).Should(Equal(corev1.PodRunning))
-                       g.Eventually(IntegrationLogs(t, ctx, ns, 
"cron-fallback"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+                       g.Eventually(LastIntegrationCronLogs(t, ctx, ns, 
"cron-quartz")).Should(ContainSubstring("Magicstring!"))
                        g.Eventually(DeleteIntegrations(t, ctx, 
ns)).Should(Equal(0))
                })
 
diff --git a/e2e/common/traits/files/cron-fallback.yaml 
b/e2e/common/traits/files/cron-fallback.yaml
index 64deab4e7..eb20e103a 100644
--- a/e2e/common/traits/files/cron-fallback.yaml
+++ b/e2e/common/traits/files/cron-fallback.yaml
@@ -18,6 +18,8 @@
 - from:
     uri: "cron:tab"
     parameters:
+      # as it runs every second, won't be creating a
+      # Kubernetes CronJob
       schedule: "0/1 * * * * ?"
     steps:
       - setHeader:
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 594af320b..1fefb0660 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -431,6 +431,25 @@ func IntegrationLogs(t *testing.T, ctx context.Context, 
ns, name string) func()
        }
 }
 
+func LastIntegrationCronLogs(t *testing.T, ctx context.Context, ns, name 
string) func() string {
+       return func() string {
+               pod := LastIntegrationCronPod(t, ctx, ns, name)()
+               if pod == nil {
+                       return ""
+               }
+
+               options := corev1.PodLogOptions{
+                       TailLines: ptr.To(int64(100)),
+               }
+
+               if len(pod.Spec.Containers) > 1 {
+                       options.Container = pod.Spec.Containers[0].Name
+               }
+
+               return Logs(t, ctx, ns, pod.Name, options)()
+       }
+}
+
 func OperatorLogs(t *testing.T, ctx context.Context, ns string) func() string {
        return func() string {
                pod := OperatorPod(t, ctx, ns)()
@@ -572,6 +591,20 @@ func IntegrationPod(t *testing.T, ctx context.Context, ns 
string, name string) f
        }
 }
 
+func LastIntegrationCronPod(t *testing.T, ctx context.Context, ns string, name 
string) func() *corev1.Pod {
+       return func() *corev1.Pod {
+               pods := IntegrationPodsSucceeded(t, ctx, ns, name)()
+               if len(pods) == 0 {
+                       return nil
+               }
+
+               sort.SliceStable(pods, func(i, j int) bool {
+                       return 
pods[i].GetCreationTimestamp().Time.After(pods[j].GetCreationTimestamp().Time)
+               })
+               return &pods[0]
+       }
+}
+
 func IntegrationPodHas(t *testing.T, ctx context.Context, ns string, name 
string, predicate func(pod *corev1.Pod) bool) func() bool {
        return func() bool {
                pod := IntegrationPod(t, ctx, ns, name)()
@@ -602,6 +635,21 @@ func IntegrationPods(t *testing.T, ctx context.Context, ns 
string, name string)
        }
 }
 
+func IntegrationPodsSucceeded(t *testing.T, ctx context.Context, ns string, 
name string) func() []corev1.Pod {
+       return func() []corev1.Pod {
+               pods := IntegrationPods(t, ctx, ns, name)
+
+               completedPods := []corev1.Pod{}
+               for _, pod := range pods() {
+                       if pod.Status.Phase == corev1.PodSucceeded || 
pod.Status.Phase == corev1.PodFailed {
+                               completedPods = append(completedPods, pod)
+                       }
+               }
+
+               return completedPods
+       }
+}
+
 func IntegrationPodsNumbers(t *testing.T, ctx context.Context, ns string, name 
string) func() *int32 {
        return func() *int32 {
                i := int32(len(IntegrationPods(t, ctx, ns, name)()))

Reply via email to