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

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

commit 7cfcd64e615a7f173c34acf06c1f453c63f2728f
Author: Gaelle Fournier <[email protected]>
AuthorDate: Fri May 31 17:23:10 2024 +0200

    feat(e2e): Rewrite tekton test to use run command
---
 e2e/advanced/files/camel-k-tekton.yaml | 40 +++++++++++++++++++++++++++
 e2e/advanced/tekton_test.go            | 49 +++++++++++++++++++++++++++++-----
 e2e/support/test_support.go            | 49 +++++++++++++++++++++++++++++++---
 3 files changed, 128 insertions(+), 10 deletions(-)

diff --git a/e2e/advanced/files/camel-k-tekton.yaml 
b/e2e/advanced/files/camel-k-tekton.yaml
new file mode 100644
index 000000000..6cee0a139
--- /dev/null
+++ b/e2e/advanced/files/camel-k-tekton.yaml
@@ -0,0 +1,40 @@
+---
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: camel-k-tekton
+---
+kind: Role
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  name: camel-k-integrations
+rules:
+- apiGroups:
+  - camel.apache.org
+  resources:
+  - integrations
+  verbs:
+  - create
+  - get
+  - list
+  - patch
+  - update
+  - watch
+- apiGroups:
+  - camel.apache.org
+  resources:
+  - camelcatalogs
+  verbs:
+  - list
+---
+kind: RoleBinding
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  name: camel-k-tekton-integrations
+subjects:
+- kind: ServiceAccount
+  name: camel-k-tekton
+roleRef:
+  kind: Role
+  name: camel-k-integrations
+  apiGroup: rbac.authorization.k8s.io
\ No newline at end of file
diff --git a/e2e/advanced/tekton_test.go b/e2e/advanced/tekton_test.go
index 484dc91fd..a2692fb6b 100644
--- a/e2e/advanced/tekton_test.go
+++ b/e2e/advanced/tekton_test.go
@@ -24,11 +24,15 @@ package advanced
 
 import (
        "context"
+       "os"
        "testing"
 
        . "github.com/onsi/gomega"
+       "github.com/stretchr/testify/require"
 
        . "github.com/apache/camel-k/v2/e2e/support"
+       v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+       corev1 "k8s.io/api/core/v1"
 )
 
 // TestTektonLikeBehavior verifies that the kamel binary can be invoked from 
within the Camel K image.
@@ -37,13 +41,46 @@ func TestTektonLikeBehavior(t *testing.T) {
        t.Parallel()
 
        WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
-               g.Expect(CreateOperatorServiceAccount(t, ctx, ns)).To(Succeed())
-               g.Expect(CreateOperatorRole(t, ctx, ns)).To(Succeed())
-               g.Expect(CreateOperatorRoleBinding(t, ctx, ns)).To(Succeed())
-
-               g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil())
-               g.Expect(CreateKamelPod(t, ctx, ns, "tekton-task", "install", 
"--skip-cluster-setup", "--olm=false", "--force")).To(Succeed())
+               operatorID := "camel-k-tekton-like"
 
+               g.Expect(KamelInstallWithID(t, ctx, operatorID, 
ns)).To(Succeed())
                g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil())
+
+               // Store a configmap holding an integration source
+               var cmData = make(map[string][]byte)
+               source, err := os.ReadFile("./files/Java.java")
+               require.NoError(t, err)
+               cmData["Java.java"] = source
+               err = CreateBinaryConfigmap(t, ctx, ns, "integration-file", 
cmData)
+               require.NoError(t, err)
+               integration := v1.ValueSource{
+                       ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
+                               LocalObjectReference: 
corev1.LocalObjectReference{
+                                       Name: "integration-file",
+                               },
+                               Key: "Java.java",
+                       },
+               }
+               t.Run("Run tekton task like delegate build and run to 
operator", func(t *testing.T) {
+                       name := RandomizedSuffixName("java-tekton-basic")
+                       g.Expect(CreateKamelPodWithIntegrationSource(t, ctx, 
ns, "tekton-task-basic", integration, "run", "/tmp/Java.java", "--name", name, 
"--operator-id", operatorID)).To(Succeed())
+                       g.Eventually(IntegrationPodPhase(t, ctx, ns, name), 
TestTimeoutLong).Should(Equal(corev1.PodRunning))
+                       g.Eventually(IntegrationConditionStatus(t, ctx, ns, 
name, v1.IntegrationConditionReady), 
TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+                       g.Eventually(IntegrationLogs(t, ctx, ns, name), 
TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+               })
+               t.Run("Run tekton task like delegate run to operator", func(t 
*testing.T) {
+                       name := RandomizedSuffixName("java-tekton-run")
+                       // Use an external image as source
+                       externalImage := "quay.io/fuse_qe/echo-server:0.3.3"
+                       g.Expect(CreateKamelPodWithIntegrationSource(t, ctx, 
ns, "tekton-task-run", integration, "run", "/tmp/Java.java", "-t", 
"container.image="+externalImage, "--name", name, "--operator-id", 
operatorID)).To(Succeed())
+                       g.Eventually(IntegrationPodPhase(t, ctx, ns, name), 
TestTimeoutLong).Should(Equal(corev1.PodRunning))
+                       g.Eventually(IntegrationConditionStatus(t, ctx, ns, 
name, v1.IntegrationConditionReady), 
TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+                       g.Eventually(IntegrationLogs(t, ctx, ns, name), 
TestTimeoutShort).Should(ContainSubstring("Echo"))
+                       tektonIntegrationKitName := IntegrationKit(t, ctx, ns, 
name)()
+                       g.Expect(tektonIntegrationKitName).ToNot(BeEmpty())
+                       tektonIntegrationKitImage := KitImage(t, ctx, ns, 
tektonIntegrationKitName)()
+                       g.Expect(tektonIntegrationKitImage).ToNot(BeEmpty())
+                       g.Eventually(Kit(t, ctx, ns, 
tektonIntegrationKitName)().Status.Image, 
TestTimeoutShort).Should(Equal(externalImage))
+               })
        })
 }
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 4f7d950b0..36f92929b 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -2685,7 +2685,46 @@ func CreateOperatorRoleBinding(t *testing.T, ctx 
context.Context, ns string) err
        return nil
 }
 
-func CreateKamelPod(t *testing.T, ctx context.Context, ns string, name string, 
command ...string) error {
+// CreateKamelPodWithIntegrationSource generates and deploy a Pod from current 
Camel K controller image that will run a `kamel xxxx` command.
+// The integration parameter represent an Integration source file contained in 
a ConfigMap or Secret defined and mounted on the as a Volume.
+func CreateKamelPodWithIntegrationSource(t *testing.T, ctx context.Context, ns 
string, name string, integration v1.ValueSource, command ...string) error {
+       // This line prevents controller-runtime from complaining about 
log.SetLogger never being called
+       logf.SetLogger(zap.New(zap.UseDevMode(true)))
+
+       var volumes []corev1.Volume
+       if integration.SecretKeyRef != nil {
+               volumes = []corev1.Volume{
+                       {
+                               Name: "integration-source-volume",
+                               VolumeSource: corev1.VolumeSource{
+                                       Secret: &corev1.SecretVolumeSource{
+                                               SecretName: 
integration.SecretKeyRef.Name,
+                                       },
+                               },
+                       },
+               }
+       } else {
+               volumes = []corev1.Volume{
+                       {
+                               Name: "integration-source-volume",
+                               VolumeSource: corev1.VolumeSource{
+                                       ConfigMap: 
&corev1.ConfigMapVolumeSource{
+                                               LocalObjectReference: 
integration.ConfigMapKeyRef.LocalObjectReference,
+                                       },
+                               },
+                       },
+               }
+       }
+
+       var volumeMounts []corev1.VolumeMount
+       volumeMounts = []corev1.VolumeMount{
+               {
+                       Name:      "integration-source-volume",
+                       MountPath: "/tmp/",
+                       ReadOnly:  true,
+               },
+       }
+
        args := command
        for _, hook := range KamelHooks {
                args = hook(args)
@@ -2704,11 +2743,13 @@ func CreateKamelPod(t *testing.T, ctx context.Context, 
ns string, name string, c
                        RestartPolicy:      corev1.RestartPolicyNever,
                        Containers: []corev1.Container{
                                {
-                                       Name:    "kamel-runner",
-                                       Image:   TestImageName + ":" + 
TestImageVersion,
-                                       Command: append([]string{"kamel"}, 
args...),
+                                       Name:         "kamel-runner",
+                                       Image:        TestImageName + ":" + 
TestImageVersion,
+                                       Command:      append([]string{"kamel"}, 
args...),
+                                       VolumeMounts: volumeMounts,
                                },
                        },
+                       Volumes: volumes,
                },
        }
        return TestClient(t).Create(ctx, &pod)

Reply via email to