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/03/19 17:03:14 UTC

[camel-k] 01/05: test: Add toleration trait e2e tests

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 5acde800984d4717f759b7d9b84a5adbc506743c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Mar 15 11:55:39 2021 +0100

    test: Add toleration trait e2e tests
---
 e2e/common/traits/toleration_test.go | 128 ++++++++++++++++++++++++-----------
 e2e/support/test_support.go          |  19 ++++++
 2 files changed, 107 insertions(+), 40 deletions(-)

diff --git a/e2e/common/traits/toleration_test.go b/e2e/common/traits/toleration_test.go
index b0469d4..50a5386 100644
--- a/e2e/common/traits/toleration_test.go
+++ b/e2e/common/traits/toleration_test.go
@@ -25,8 +25,10 @@ import (
 	"testing"
 
 	. "github.com/onsi/gomega"
+	. "github.com/onsi/gomega/gstruct"
 
 	v1 "k8s.io/api/core/v1"
+	"k8s.io/utils/pointer"
 
 	. "github.com/apache/camel-k/e2e/support"
 	camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -35,46 +37,92 @@ import (
 func TestTolerationTrait(t *testing.T) {
 	WithNewTestNamespace(t, func(ns string) {
 		Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
-		var wait int64 = 300
-
-		InvokeUserTestCode(t, ns, func(ns string) {
-			t.Run("Run Java with node toleration operation exists", func(t *testing.T) {
-				Expect(Kamel("run", "-n", ns, "files/Java.java",
-					"--name", "java1",
-					"-t", "toleration.enabled=true",
-					"-t", "toleration.taints=camel.apache.org/master:NoExecute:300").Execute()).To(Succeed())
-				Eventually(IntegrationPodPhase(ns, "java1"), TestTimeoutLong).Should(Equal(v1.PodRunning))
-				Eventually(IntegrationCondition(ns, "java1", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
-				Eventually(IntegrationLogs(ns, "java1"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
-
-				pod := IntegrationPod(ns, "java1")()
-				Expect(pod.Spec.Tolerations).NotTo(BeNil())
-
-				Expect(pod.Spec.Tolerations).To(ContainElement(v1.Toleration{
-					"camel.apache.org/master", v1.TolerationOpExists, "", v1.TaintEffectNoExecute, &wait,
-				}))
-
-				Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
-			})
-
-			t.Run("Run Java with node toleration operation equals", func(t *testing.T) {
-				Expect(Kamel("run", "-n", ns, "files/Java.java",
-					"--name", "java2",
-					"-t", "toleration.enabled=true",
-					"-t", "toleration.taints=camel.apache.org/master=test:NoExecute:300").Execute()).To(Succeed())
-				Eventually(IntegrationPodPhase(ns, "java2"), TestTimeoutLong).Should(Equal(v1.PodRunning))
-				Eventually(IntegrationCondition(ns, "java2", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
-				Eventually(IntegrationLogs(ns, "java2"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
-
-				pod := IntegrationPod(ns, "java2")()
-				Expect(pod.Spec.Tolerations).NotTo(BeNil())
-
-				Expect(pod.Spec.Tolerations).To(ContainElement(v1.Toleration{
-					"camel.apache.org/master", v1.TolerationOpEqual, "test", v1.TaintEffectNoExecute, &wait,
-				}))
-
-				Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
-			})
+
+		t.Run("Run Java with node toleration operation exists", func(t *testing.T) {
+			name := "java1"
+			Expect(Kamel("run", "-n", ns, "files/Java.java",
+				"--name", name,
+				"-t", "toleration.enabled=true",
+				"-t", "toleration.taints=camel.apache.org/master:NoExecute:300",
+			).Execute()).To(Succeed())
+			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!"))
+
+			pod := IntegrationPod(ns, name)()
+			Expect(pod.Spec.Tolerations).NotTo(BeNil())
+
+			Expect(pod.Spec.Tolerations).To(ContainElement(v1.Toleration{
+				Key:               "camel.apache.org/master",
+				Operator:          v1.TolerationOpExists,
+				Effect:            v1.TaintEffectNoExecute,
+				TolerationSeconds: pointer.Int64Ptr(300),
+			}))
+		})
+
+		t.Run("Run Java with node toleration operation equals", func(t *testing.T) {
+			name := "java2"
+			Expect(Kamel("run", "-n", ns, "files/Java.java",
+				"--name", name,
+				"-t", "toleration.enabled=true",
+				"-t", "toleration.taints=camel.apache.org/master=test:NoExecute:300",
+			).Execute()).To(Succeed())
+			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!"))
+
+			pod := IntegrationPod(ns, name)()
+			Expect(pod.Spec.Tolerations).NotTo(BeNil())
+
+			Expect(pod.Spec.Tolerations).To(ContainElement(v1.Toleration{
+				Key:      "camel.apache.org/master",
+				Operator: v1.TolerationOpEqual,
+				Value:    "test", Effect: v1.TaintEffectNoExecute,
+				TolerationSeconds: pointer.Int64Ptr(300),
+			}))
 		})
+
+		t.Run("Run Java with master node toleration", func(t *testing.T) {
+			name := "java3"
+			Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
+			Expect(Kamel("run", "-n", ns, "files/Java.java",
+				"--name", name,
+				// Use the affinity trait to force the scheduling of the Integration pod onto a master node
+				"-t", "affinity.enabled=true",
+				"-t", "affinity.node-affinity-labels=node-role.kubernetes.io/master",
+				// And tolerate the corresponding taint
+				"-t", "toleration.enabled=true",
+				"-t", "toleration.taints=node-role.kubernetes.io/master:NoSchedule",
+			).Execute()).To(Succeed())
+
+			Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+			Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+			pod := IntegrationPod(ns, name)()
+			Expect(pod).NotTo(BeNil())
+
+			// Check the Integration pod contains the toleration
+			Expect(pod.Spec.Tolerations).To(ContainElement(v1.Toleration{
+				Key:      "node-role.kubernetes.io/master",
+				Operator: v1.TolerationOpExists,
+				Effect:   v1.TaintEffectNoSchedule,
+			}))
+
+			// Check the Integration pod is running on a master node
+			node := Node(pod.Spec.NodeName)()
+			Expect(node).NotTo(BeNil())
+			Expect(node).To(PointTo(MatchFields(IgnoreExtras, Fields{
+				"Spec": MatchFields(IgnoreExtras, Fields{
+					"Taints": ContainElement(v1.Taint{
+						Key:    "node-role.kubernetes.io/master",
+						Effect: v1.TaintEffectNoSchedule,
+					}),
+				}),
+			})))
+		})
+
+		// Clean up
+		Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
 	})
 }
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 4431d0b..dd7365c 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -382,6 +382,25 @@ func Lease(ns string, name string) func() *coordination.Lease {
 	}
 }
 
+func Node(name string) func() *corev1.Node {
+	return func() *corev1.Node {
+		node := &corev1.Node{
+			TypeMeta: metav1.TypeMeta{
+				Kind:       "Node",
+				APIVersion: corev1.SchemeGroupVersion.String(),
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Name: name,
+			},
+		}
+		err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(node), node)
+		if err != nil {
+			panic(err)
+		}
+		return node
+	}
+}
+
 func Service(ns string, name string) func() *corev1.Service {
 	return func() *corev1.Service {
 		svc := corev1.Service{}