You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2019/11/28 07:40:49 UTC

[camel-k] 02/07: Fix #613: add cluster-type option and e2e test with docker hub

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

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

commit 20250981056e8d23d1ffc48f14a6a2c3e205a3b2
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Sat Nov 23 01:45:15 2019 +0100

    Fix #613: add cluster-type option and e2e test with docker hub
---
 e2e/docker_hub_test.go                             | 59 ++++++++++++++++++++++
 .../camel/v1alpha1/integrationplatform_types.go    |  4 ++
 pkg/cmd/install.go                                 | 13 ++++-
 pkg/install/common.go                              | 17 +++++++
 pkg/install/operator.go                            | 14 ++---
 5 files changed, 99 insertions(+), 8 deletions(-)

diff --git a/e2e/docker_hub_test.go b/e2e/docker_hub_test.go
new file mode 100644
index 0000000..a5e8ec2
--- /dev/null
+++ b/e2e/docker_hub_test.go
@@ -0,0 +1,59 @@
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package e2e
+
+import (
+	"os"
+	"testing"
+	"time"
+
+	. "github.com/onsi/gomega"
+	v1 "k8s.io/api/core/v1"
+)
+
+func TestRunWithDockerHubRepo(t *testing.T) {
+	user := os.Getenv("TEST_DOCKER_HUB_USERNAME")
+	pass := os.Getenv("TEST_DOCKER_HUB_PASSWORD")
+	if user == "" || pass == "" {
+		t.Skip("no docker hub credentials: skipping")
+	} else {
+		withNewTestNamespace(func(ns string) {
+			RegisterTestingT(t)
+			Expect(kamel("install",
+				"-n", ns,
+				"--registry", "docker.io",
+				"--organization", user,
+				"--registry-auth-username", user,
+				"--registry-auth-password", pass,
+				"--cluster-type", "kubernetes").
+				Execute()).Should(BeNil())
+
+			Expect(kamel("run", "-n", ns, "files/groovy.groovy").Execute()).Should(BeNil())
+			Eventually(integrationPodPhase(ns, "groovy"), 5*time.Minute).Should(Equal(v1.PodRunning))
+			Eventually(integrationLogs(ns, "groovy"), 1*time.Minute).Should(ContainSubstring("Magicstring!"))
+			Eventually(integrationPodImage(ns, "groovy"), 1*time.Minute).Should(HavePrefix("docker.io"))
+
+			Expect(kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
+		})
+	}
+
+}
diff --git a/pkg/apis/camel/v1alpha1/integrationplatform_types.go b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
index ae9be5e..bfd7cf1 100644
--- a/pkg/apis/camel/v1alpha1/integrationplatform_types.go
+++ b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
@@ -78,6 +78,10 @@ const (
 	IntegrationPlatformClusterKubernetes = "Kubernetes"
 )
 
+// AllIntegrationPlatformClusters --
+var AllIntegrationPlatformClusters = []IntegrationPlatformCluster{IntegrationPlatformClusterOpenShift, IntegrationPlatformClusterKubernetes}
+
+
 // TraitProfile represents lists of traits that are enabled for the specific installation/integration
 type TraitProfile string
 
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index f90b763..e448a08 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -56,6 +56,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command {
 
 	cmd.Flags().BoolVarP(&impl.wait, "wait", "w", false, "Waits for the platform to be running")
 	cmd.Flags().BoolVar(&impl.clusterSetupOnly, "cluster-setup", false, "Execute cluster-wide operations only (may require admin rights)")
+	cmd.Flags().StringVar(&impl.clusterType, "cluster-type", "", "Set explicitly the cluster type to Kubernetes or OpenShift")
 	cmd.Flags().BoolVar(&impl.skipOperatorSetup, "skip-operator-setup", false, "Do not install the operator in the namespace (in case there's a global one)")
 	cmd.Flags().BoolVar(&impl.skipClusterSetup, "skip-cluster-setup", false, "Skip the cluster-setup phase")
 	cmd.Flags().BoolVar(&impl.exampleSetup, "example", false, "Install example integration")
@@ -103,6 +104,7 @@ type installCmdOptions struct {
 	*RootCmdOptions
 	wait              bool
 	clusterSetupOnly  bool
+	clusterType       string
 	skipOperatorSetup bool
 	skipClusterSetup  bool
 	exampleSetup      bool
@@ -165,6 +167,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 				CustomImage: o.operatorImage,
 				Namespace:   namespace,
 				Global:      o.global,
+				ClusterType: o.clusterType,
 			}
 			err = install.OperatorOrCollect(o.Context, c, cfg, collection)
 			if err != nil {
@@ -184,7 +187,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 			}
 		}
 
-		platform, err := install.PlatformOrCollect(o.Context, c, namespace, o.registry, collection)
+		platform, err := install.PlatformOrCollect(o.Context, c, o.clusterType, namespace, o.registry, collection)
 		if err != nil {
 			return err
 		}
@@ -256,6 +259,14 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 			platform.Spec.Build.HTTPProxySecret = o.httpProxySecret
 		}
 
+		if o.clusterType != "" {
+			for _, c := range v1alpha1.AllIntegrationPlatformClusters {
+				if strings.ToLower(string(c)) == strings.ToLower(o.clusterType) {
+					platform.Spec.Cluster = c
+				}
+			}
+		}
+
 		kanikoBuildCacheFlag := cobraCmd.Flags().Lookup("kaniko-build-cache")
 
 		defaultKanikoBuildCache := true
diff --git a/pkg/install/common.go b/pkg/install/common.go
index b6d385f..a9d36c7 100644
--- a/pkg/install/common.go
+++ b/pkg/install/common.go
@@ -19,11 +19,13 @@ package install
 
 import (
 	"context"
+	"strings"
 
 	"github.com/apache/camel-k/deploy"
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 	"github.com/apache/camel-k/pkg/client"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/openshift"
 
 	"k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -111,3 +113,18 @@ func RuntimeObjectOrCollect(ctx context.Context, c client.Client, namespace stri
 	}
 	return err
 }
+
+
+func isOpenShift(c client.Client, clusterType string) (bool, error) {
+	var res bool
+	var err error
+	if clusterType != "" {
+		res = strings.ToLower(clusterType) == strings.ToLower(string(v1alpha1.IntegrationPlatformClusterOpenShift))
+	} else {
+		res, err = openshift.IsOpenShift(c)
+		if err != nil {
+			return false, err
+		}
+	}
+	return res, nil
+}
\ No newline at end of file
diff --git a/pkg/install/operator.go b/pkg/install/operator.go
index 27580f3..eb17081 100644
--- a/pkg/install/operator.go
+++ b/pkg/install/operator.go
@@ -23,7 +23,7 @@ import (
 	"strings"
 
 	v1 "k8s.io/api/apps/v1"
-	v1beta1 "k8s.io/api/rbac/v1beta1"
+	"k8s.io/api/rbac/v1beta1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 
@@ -34,7 +34,6 @@ import (
 	"github.com/apache/camel-k/pkg/util/knative"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/apache/camel-k/pkg/util/minishift"
-	"github.com/apache/camel-k/pkg/util/openshift"
 )
 
 // OperatorConfiguration --
@@ -42,6 +41,7 @@ type OperatorConfiguration struct {
 	CustomImage string
 	Namespace   string
 	Global      bool
+	ClusterType string
 }
 
 // Operator installs the operator resources in the given namespace
@@ -103,7 +103,7 @@ func OperatorOrCollect(ctx context.Context, c client.Client, cfg OperatorConfigu
 		return o
 	}
 
-	isOpenshift, err := openshift.IsOpenShift(c)
+	isOpenshift, err := isOpenShift(c, cfg.ClusterType)
 	if err != nil {
 		return err
 	}
@@ -153,14 +153,14 @@ func installKnative(ctx context.Context, c client.Client, namespace string, cust
 }
 
 // Platform installs the platform custom resource
-func Platform(ctx context.Context, c client.Client, namespace string, registry v1alpha1.IntegrationPlatformRegistrySpec) (*v1alpha1.IntegrationPlatform, error) {
-	return PlatformOrCollect(ctx, c, namespace, registry, nil)
+func Platform(ctx context.Context, c client.Client, clusterType string, namespace string, registry v1alpha1.IntegrationPlatformRegistrySpec) (*v1alpha1.IntegrationPlatform, error) {
+	return PlatformOrCollect(ctx, c, clusterType, namespace, registry, nil)
 }
 
 // PlatformOrCollect --
 // nolint: lll
-func PlatformOrCollect(ctx context.Context, c client.Client, namespace string, registry v1alpha1.IntegrationPlatformRegistrySpec, collection *kubernetes.Collection) (*v1alpha1.IntegrationPlatform, error) {
-	isOpenshift, err := openshift.IsOpenShift(c)
+func PlatformOrCollect(ctx context.Context, c client.Client, clusterType string, namespace string, registry v1alpha1.IntegrationPlatformRegistrySpec, collection *kubernetes.Collection) (*v1alpha1.IntegrationPlatform, error) {
+	isOpenshift, err := isOpenShift(c, clusterType)
 	if err != nil {
 		return nil, err
 	}