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 2021/02/19 10:25:03 UTC

[camel-k] branch master updated (9ff10c5 -> 0c273e3)

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

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


    from 9ff10c5  Wait for operator to start before scaling it to zero
     new 75e85b1  chore(test): Add integration scaling e2e tests
     new 36b3332  fix(e2e): Fix APIVersion field in Pod struct
     new 0c273e3  fix(e2e): Clean-up namespace after kamel run tests

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 e2e/common/run_test.go      |  11 +++--
 e2e/common/scale_test.go    | 111 ++++++++++++++++++++++++++++++++++++++++++++
 e2e/support/test_support.go |  39 ++++++++++++++--
 3 files changed, 153 insertions(+), 8 deletions(-)
 create mode 100644 e2e/common/scale_test.go


[camel-k] 02/03: fix(e2e): Fix APIVersion field in Pod struct

Posted by as...@apache.org.
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 36b3332bb2fd5c6425b38aeccc0c18c9cd26f96c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Feb 19 09:30:57 2021 +0100

    fix(e2e): Fix APIVersion field in Pod struct
---
 e2e/support/test_support.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 7a5ef96..0849e7b 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -887,7 +887,7 @@ func CreateKamelPod(ns string, name string, command ...string) error {
 	pod := corev1.Pod{
 		TypeMeta: metav1.TypeMeta{
 			Kind:       "Pod",
-			APIVersion: v1.SchemeGroupVersion.String(),
+			APIVersion: corev1.SchemeGroupVersion.String(),
 		},
 		ObjectMeta: metav1.ObjectMeta{
 			Namespace: ns,


[camel-k] 03/03: fix(e2e): Clean-up namespace after kamel run tests

Posted by as...@apache.org.
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 0c273e369f6ffbe91c446a24bdd56da8402b6f5d
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Feb 19 09:32:12 2021 +0100

    fix(e2e): Clean-up namespace after kamel run tests
---
 e2e/common/run_test.go | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/e2e/common/run_test.go b/e2e/common/run_test.go
index 78e60a2..de43ee6 100644
--- a/e2e/common/run_test.go
+++ b/e2e/common/run_test.go
@@ -24,13 +24,15 @@ package common
 import (
 	"testing"
 
-	. "github.com/apache/camel-k/e2e/support"
-	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	. "github.com/onsi/gomega"
+
 	v1 "k8s.io/api/core/v1"
+
+	. "github.com/apache/camel-k/e2e/support"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
 
-func TestRunExamplesFromGitHUB(t *testing.T) {
+func TestRunExamplesFromGitHub(t *testing.T) {
 	WithNewTestNamespace(t, func(ns string) {
 		Expect(Kamel("install", "-n", ns).Execute()).Should(BeNil())
 
@@ -73,5 +75,8 @@ func TestRunExamplesFromGitHUB(t *testing.T) {
 			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Tick!"))
 			Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
 		})
+
+		// Cleanup
+		Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
 	})
 }


[camel-k] 01/03: chore(test): Add integration scaling e2e tests

Posted by as...@apache.org.
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 75e85b16b826423b970ae0c14adeeccbbdd900d8
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Feb 18 19:30:21 2021 +0100

    chore(test): Add integration scaling e2e tests
---
 e2e/common/scale_test.go    | 111 ++++++++++++++++++++++++++++++++++++++++++++
 e2e/support/test_support.go |  37 +++++++++++++--
 2 files changed, 144 insertions(+), 4 deletions(-)

diff --git a/e2e/common/scale_test.go b/e2e/common/scale_test.go
new file mode 100644
index 0000000..cc77db1
--- /dev/null
+++ b/e2e/common/scale_test.go
@@ -0,0 +1,111 @@
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "knative"
+
+/*
+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 common
+
+import (
+	"testing"
+
+	. "github.com/onsi/gomega"
+	"github.com/onsi/gomega/gstruct"
+	"github.com/stretchr/testify/assert"
+
+	v1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/types"
+
+	"k8s.io/client-go/dynamic"
+	"k8s.io/client-go/restmapper"
+	"k8s.io/client-go/scale"
+
+	. "github.com/apache/camel-k/e2e/support"
+	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/pkg/client/camel/clientset/versioned"
+)
+
+func TestIntegrationScale(t *testing.T) {
+	WithNewTestNamespace(t, func(ns string) {
+		name := "java"
+		Expect(Kamel("install", "-n", ns).Execute()).Should(BeNil())
+		Expect(Kamel("run", "-n", ns, "files/Java.java", "--name", name).Execute()).Should(BeNil())
+		Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(v1.PodRunning))
+		Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+		Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+		t.Run("Scale integration with polymorphic client", func(t *testing.T) {
+			// Polymorphic scale client
+			groupResources, err := restmapper.GetAPIGroupResources(TestClient().Discovery())
+			assert.Nil(t, err)
+			mapper := restmapper.NewDiscoveryRESTMapper(groupResources)
+			resolver := scale.NewDiscoveryScaleKindResolver(TestClient().Discovery())
+			scaleClient, err := scale.NewForConfig(TestClient().GetConfig(), mapper, dynamic.LegacyAPIPathResolverFunc, resolver)
+			assert.Nil(t, err)
+
+			// Patch the integration scale subresource
+			patch := "{\"spec\":{\"replicas\":2}}"
+			_, err = scaleClient.Scales(ns).Patch(TestContext, camelv1.SchemeGroupVersion.WithResource("integrations"), name, types.MergePatchType, []byte(patch), metav1.PatchOptions{})
+			if err != nil {
+				t.Fatal(err)
+			}
+
+			// Check the Integration scale subresource Spec field
+			Eventually(IntegrationSpecReplicas(ns, name), TestTimeoutShort).
+				Should(gstruct.PointTo(BeNumerically("==", 2)))
+			// Then check it cascades into the Deployment scale
+			Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(2))
+			// Finally check it cascades into the Integration scale subresource Status field
+			Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
+				Should(gstruct.PointTo(BeNumerically("==", 2)))
+		})
+
+		t.Run("Scale integration with Camel K client", func(t *testing.T) {
+			camel, err := versioned.NewForConfig(TestClient().GetConfig())
+			if err != nil {
+				t.Fatal(err)
+			}
+
+			// Getter
+			integrationScale, err := camel.CamelV1().Integrations(ns).GetScale(TestContext, name, metav1.GetOptions{})
+			Expect(integrationScale).ShouldNot(BeNil())
+			Expect(integrationScale.Spec.Replicas).Should(BeNumerically("==", 2))
+			Expect(integrationScale.Status.Replicas).Should(BeNumerically("==", 2))
+
+			// Setter
+			integrationScale.Spec.Replicas = 1
+			integrationScale, err = camel.CamelV1().Integrations(ns).UpdateScale(TestContext, name, integrationScale, metav1.UpdateOptions{})
+			if err != nil {
+				t.Fatal(err)
+			}
+
+			// Check the Integration scale subresource Spec field
+			Eventually(IntegrationSpecReplicas(ns, name), TestTimeoutShort).
+				Should(gstruct.PointTo(BeNumerically("==", 1)))
+			// Then check it cascades into the Deployment scale
+			Eventually(IntegrationPods(ns, name), TestTimeoutMedium).Should(HaveLen(1))
+			// Finally check it cascades into the Integration scale subresource Status field
+			Eventually(IntegrationStatusReplicas(ns, name), TestTimeoutShort).
+				Should(gstruct.PointTo(BeNumerically("==", 1)))
+		})
+
+		// Cleanup
+		Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
+	})
+}
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 21a85d8..7a5ef96 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -34,11 +34,10 @@ import (
 	"testing"
 	"time"
 
-	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
-	"github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/google/uuid"
 	"github.com/onsi/gomega"
 	"github.com/spf13/cobra"
+
 	appsv1 "k8s.io/api/apps/v1"
 	"k8s.io/api/batch/v1beta1"
 	corev1 "k8s.io/api/core/v1"
@@ -46,6 +45,7 @@ import (
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
+
 	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
 
 	eventing "knative.dev/eventing/pkg/apis/eventing/v1beta1"
@@ -57,10 +57,12 @@ import (
 
 	"github.com/apache/camel-k/e2e/support/util"
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"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/kubernetes"
 	"github.com/apache/camel-k/pkg/util/log"
 	"github.com/apache/camel-k/pkg/util/openshift"
 
@@ -260,6 +262,16 @@ func IntegrationPodImage(ns string, name string) func() string {
 
 func IntegrationPod(ns string, name string) func() *corev1.Pod {
 	return func() *corev1.Pod {
+		pods := IntegrationPods(ns, name)()
+		if len(pods) == 0 {
+			return nil
+		}
+		return &pods[0]
+	}
+}
+
+func IntegrationPods(ns string, name string) func() []corev1.Pod {
+	return func() []corev1.Pod {
 		lst := corev1.PodList{
 			TypeMeta: metav1.TypeMeta{
 				Kind:       "Pod",
@@ -274,10 +286,27 @@ func IntegrationPod(ns string, name string) func() *corev1.Pod {
 		if err != nil {
 			panic(err)
 		}
-		if len(lst.Items) == 0 {
+		return lst.Items
+	}
+}
+
+func IntegrationSpecReplicas(ns string, name string) func() *int32 {
+	return func() *int32 {
+		it := Integration(ns, name)()
+		if it == nil {
 			return nil
 		}
-		return &lst.Items[0]
+		return it.Spec.Replicas
+	}
+}
+
+func IntegrationStatusReplicas(ns string, name string) func() *int32 {
+	return func() *int32 {
+		it := Integration(ns, name)()
+		if it == nil {
+			return nil
+		}
+		return it.Status.Replicas
 	}
 }