You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/09/23 16:32:32 UTC

[camel-k] 05/07: Adding test to verify kamel inside image

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

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

commit a89e54c467c4ed4761b0ec5705afe29527ee9548
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Sep 20 09:27:44 2019 +0200

    Adding test to verify kamel inside image
---
 e2e/{test_staging_hooks.go => tekton_test.go} | 32 ++++++++-----
 e2e/test_staging_hooks.go                     | 18 +++++---
 e2e/test_support.go                           | 66 +++++++++++++++++++++++----
 3 files changed, 89 insertions(+), 27 deletions(-)

diff --git a/e2e/test_staging_hooks.go b/e2e/tekton_test.go
similarity index 58%
copy from e2e/test_staging_hooks.go
copy to e2e/tekton_test.go
index f85998b..dd4d7dc 100644
--- a/e2e/test_staging_hooks.go
+++ b/e2e/tekton_test.go
@@ -1,4 +1,4 @@
-// +build integration knative
+// +build integration
 
 // To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
 
@@ -21,15 +21,25 @@ limitations under the License.
 
 package e2e
 
-func init() {
-	// this hook can be used to test a released version of the operator, e.g. the staging version during a voting period
-	// Uncomment the following lines and change references to enable the hook
-	kamelHooks = append(kamelHooks, func(cmd []string) []string {
-		//if len(cmd) > 0 && cmd[0] == "install" {
-		//	cmd = append(cmd, "--operator-image=docker.io/camelk/camel-k:1.0.0-M1")
-		//	cmd = append(cmd, "--maven-repository=https://repository.apache.org/content/repositories/orgapachecamel-1145")
-		//}
-		return cmd
-	})
+import (
+	"testing"
+
+	. "github.com/onsi/gomega"
+)
+
+// TestTektonLikeBehavior verifies that the kamel binary can be invoked from within the Camel K image.
+// This feature is used in Tekton pipelines.
+func TestTektonLikeBehavior(t *testing.T) {
+	withNewTestNamespace(func(ns string) {
+		RegisterTestingT(t)
 
+		Expect(createOperatorServiceAccount(ns)).Should(BeNil())
+		Expect(createOperatorRole(ns)).Should(BeNil())
+		Expect(createOperatorRoleBinding(ns)).Should(BeNil())
+
+		Eventually(operatorPod(ns)).Should(BeNil())
+		Expect(createKamelPod(ns, "tekton-task", "install")).Should(BeNil())
+
+		Eventually(operatorPod(ns)).ShouldNot(BeNil())
+	})
 }
diff --git a/e2e/test_staging_hooks.go b/e2e/test_staging_hooks.go
index f85998b..a441084 100644
--- a/e2e/test_staging_hooks.go
+++ b/e2e/test_staging_hooks.go
@@ -24,12 +24,16 @@ package e2e
 func init() {
 	// this hook can be used to test a released version of the operator, e.g. the staging version during a voting period
 	// Uncomment the following lines and change references to enable the hook
-	kamelHooks = append(kamelHooks, func(cmd []string) []string {
-		//if len(cmd) > 0 && cmd[0] == "install" {
-		//	cmd = append(cmd, "--operator-image=docker.io/camelk/camel-k:1.0.0-M1")
-		//	cmd = append(cmd, "--maven-repository=https://repository.apache.org/content/repositories/orgapachecamel-1145")
-		//}
-		return cmd
-	})
+
+	//testImageName = "docker.io/camelk/camel-k"
+	//testImageVersion = "1.0.0-M2-SNAPSHOT"
+
+	//kamelHooks = append(kamelHooks, func(cmd []string) []string {
+	//	if len(cmd) > 0 && cmd[0] == "install" {
+	//		cmd = append(cmd, "--operator-image=docker.io/camelk/camel-k:1.0.0-M2-SNAPSHOT")
+	//		cmd = append(cmd, "--maven-repository=https://repository.apache.org/content/repositories/orgapachecamel-1145")
+	//	}
+	//	return cmd
+	//})
 
 }
diff --git a/e2e/test_support.go b/e2e/test_support.go
index c5db056..38e92bf 100644
--- a/e2e/test_support.go
+++ b/e2e/test_support.go
@@ -25,16 +25,17 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"io/ioutil"
 	"os"
 	"os/exec"
 	"strings"
 	"time"
 
-	"io/ioutil"
-
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	"github.com/apache/camel-k/pkg/client"
 	"github.com/apache/camel-k/pkg/cmd"
+	"github.com/apache/camel-k/pkg/install"
+	"github.com/apache/camel-k/pkg/util/defaults"
 	"github.com/apache/camel-k/pkg/util/log"
 	"github.com/apache/camel-k/pkg/util/openshift"
 	"github.com/google/uuid"
@@ -55,7 +56,10 @@ var testContext context.Context
 var testClient client.Client
 
 // kamelHooks contains hooks useful to add option to kamel commands at runtime
-var kamelHooks []func([]string)[]string
+var kamelHooks []func([]string) []string
+
+var testImageName = defaults.ImageName
+var testImageVersion = defaults.Version
 
 func init() {
 	var err error
@@ -442,25 +446,70 @@ func scaleOperator(ns string, replicas int32) func() error {
 }
 
 /*
+	Tekton
+*/
+
+func createOperatorServiceAccount(ns string) error {
+	return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-service-account.yaml")
+}
+
+func createOperatorRole(ns string) error {
+	return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-role-openshift.yaml")
+}
+
+func createOperatorRoleBinding(ns string) error {
+	return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-role-binding.yaml")
+}
+
+func createKamelPod(ns string, name string, command ...string) error {
+	args := command
+	for _, hook := range kamelHooks {
+		args = hook(args)
+	}
+	pod := v1.Pod{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "Pod",
+			APIVersion: v1.SchemeGroupVersion.String(),
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: ns,
+			Name:      name,
+		},
+		Spec: v1.PodSpec{
+			ServiceAccountName: "camel-k-operator",
+			RestartPolicy:      v1.RestartPolicyNever,
+			Containers: []v1.Container{
+				{
+					Name:    "kamel-runner",
+					Image:   testImageName + ":" + testImageVersion,
+					Command: append([]string{"kamel"}, args...),
+				},
+			},
+		},
+	}
+	return testClient.Create(testContext, &pod)
+}
+
+/*
 	Knative
- */
+*/
 
 func createKnativeChannel(ns string, name string) func() error {
 	return func() error {
 		channel := eventing.Channel{
 			TypeMeta: metav1.TypeMeta{
-				Kind: "Channel",
+				Kind:       "Channel",
 				APIVersion: eventing.SchemeGroupVersion.String(),
 			},
 			ObjectMeta: metav1.ObjectMeta{
 				Namespace: ns,
-				Name: name,
+				Name:      name,
 			},
 			Spec: eventing.ChannelSpec{
 				Provisioner: &v1.ObjectReference{
 					APIVersion: "eventing.knative.dev/v1alpha1",
-					Kind: "ClusterChannelProvisioner",
-					Name: "in-memory",
+					Kind:       "ClusterChannelProvisioner",
+					Name:       "in-memory",
 				},
 			},
 		}
@@ -468,7 +517,6 @@ func createKnativeChannel(ns string, name string) func() error {
 	}
 }
 
-
 /*
 	Namespace testing functions
 */