You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ts...@apache.org on 2022/05/12 10:50:16 UTC

[camel-k] branch main updated (442c15861 -> c19e4bfbe)

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

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


    from 442c15861 corrected typo error
     new 343784b43 fix(trait): disable NodePort by default for Service trait
     new 31acbe47e chore(e2e): format test java files
     new c19e4bfbe test(e2e): add E2E test for Service trait

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:
 docs/modules/traits/pages/service.adoc             |  2 +-
 e2e/common/traits/files/Java.java                  | 14 ++++----
 e2e/common/traits/files/Master.java                | 14 ++++----
 e2e/common/traits/files/PlatformHttpServer.java    | 11 ++++---
 .../traits/{jolokia_test.go => service_test.go}    | 38 ++++++++++++----------
 pkg/trait/service.go                               |  4 +--
 pkg/trait/service_test.go                          |  8 +++--
 resources/traits.yaml                              |  2 +-
 8 files changed, 49 insertions(+), 44 deletions(-)
 copy e2e/common/traits/{jolokia_test.go => service_test.go} (55%)


[camel-k] 02/03: chore(e2e): format test java files

Posted by ts...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 31acbe47e9ee8d03b026785a533e04b8ac34b6e2
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Thu May 12 15:11:23 2022 +0900

    chore(e2e): format test java files
---
 e2e/common/traits/files/Java.java               | 14 +++++++-------
 e2e/common/traits/files/Master.java             | 14 +++++++-------
 e2e/common/traits/files/PlatformHttpServer.java | 11 ++++++-----
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/e2e/common/traits/files/Java.java b/e2e/common/traits/files/Java.java
index 66fef5fe8..30b1f459e 100644
--- a/e2e/common/traits/files/Java.java
+++ b/e2e/common/traits/files/Java.java
@@ -18,11 +18,11 @@
 import org.apache.camel.builder.RouteBuilder;
 
 public class Java extends RouteBuilder {
-  @Override
-  public void configure() throws Exception {
-	  from("timer:tick")
-	  .setHeader("m").constant("string!")
-	  .setBody().simple("Magic${header.m}")
-      .log("${body}");
-  }
+    @Override
+    public void configure() throws Exception {
+        from("timer:tick")
+            .setHeader("m").constant("string!")
+            .setBody().simple("Magic${header.m}")
+            .log("${body}");
+    }
 }
diff --git a/e2e/common/traits/files/Master.java b/e2e/common/traits/files/Master.java
index 84fdeeb05..6f3a8d1ed 100644
--- a/e2e/common/traits/files/Master.java
+++ b/e2e/common/traits/files/Master.java
@@ -18,11 +18,11 @@
 import org.apache.camel.builder.RouteBuilder;
 
 public class Master extends RouteBuilder {
-  @Override
-  public void configure() throws Exception {
-	  from("master:lock:timer:tick")
-	  .setHeader("m").constant("string!")
-	  .setBody().simple("Magic${header.m}")
-      .log("${body}");
-  }
+    @Override
+    public void configure() throws Exception {
+        from("master:lock:timer:tick")
+            .setHeader("m").constant("string!")
+            .setBody().simple("Magic${header.m}")
+            .log("${body}");
+    }
 }
diff --git a/e2e/common/traits/files/PlatformHttpServer.java b/e2e/common/traits/files/PlatformHttpServer.java
index 9e5251481..31d8d19f3 100644
--- a/e2e/common/traits/files/PlatformHttpServer.java
+++ b/e2e/common/traits/files/PlatformHttpServer.java
@@ -18,8 +18,9 @@
 import org.apache.camel.builder.RouteBuilder;
 
 public class PlatformHttpServer extends RouteBuilder {
-  @Override
-  public void configure() throws Exception {
-    from("platform-http:/hello?httpMethodRestrict=GET").setBody(simple("Hello ${header.name}"));
-  }
-}
\ No newline at end of file
+    @Override
+    public void configure() throws Exception {
+        from("platform-http:/hello?httpMethodRestrict=GET")
+            .setBody(simple("Hello ${header.name}"));
+    }
+}


[camel-k] 03/03: test(e2e): add E2E test for Service trait

Posted by ts...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c19e4bfbeacfc5f60414ee06cfbe600823c2a26d
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Thu May 12 15:39:17 2022 +0900

    test(e2e): add E2E test for Service trait
---
 e2e/common/traits/service_test.go | 62 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/e2e/common/traits/service_test.go b/e2e/common/traits/service_test.go
new file mode 100644
index 000000000..0ee3569c6
--- /dev/null
+++ b/e2e/common/traits/service_test.go
@@ -0,0 +1,62 @@
+//go:build integration
+// +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 traits
+
+import (
+	"testing"
+
+	. "github.com/onsi/gomega"
+
+	corev1 "k8s.io/api/core/v1"
+
+	. "github.com/apache/camel-k/e2e/support"
+)
+
+func TestServiceTrait(t *testing.T) {
+	WithNewTestNamespace(t, func(ns string) {
+		Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
+
+		t.Run("Default service (ClusterIP)", func(t *testing.T) {
+			// Service trait is enabled by default
+			Expect(Kamel("run", "-n", ns, "files/PlatformHttpServer.java").Execute()).To(Succeed())
+			Eventually(IntegrationPodPhase(ns, "platform-http-server"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+			service := Service(ns, "platform-http-server")
+			Eventually(service, TestTimeoutShort).ShouldNot(BeNil())
+			Expect(service().Spec.Type).Should(Equal(corev1.ServiceTypeClusterIP))
+
+			Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+		})
+
+		t.Run("NodePort service", func(t *testing.T) {
+			Expect(Kamel("run", "-n", ns, "files/PlatformHttpServer.java",
+				"-t", "service.enabled=true",
+				"-t", "service.node-port=true").Execute()).To(Succeed())
+			Eventually(IntegrationPodPhase(ns, "platform-http-server"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+			service := Service(ns, "platform-http-server")
+			Eventually(service, TestTimeoutShort).ShouldNot(BeNil())
+			Expect(service().Spec.Type).Should(Equal(corev1.ServiceTypeNodePort))
+
+			Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+		})
+	})
+}


[camel-k] 01/03: fix(trait): disable NodePort by default for Service trait

Posted by ts...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 343784b435beffe2a30927aa3cf94c2b10e02810
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Wed May 11 17:44:01 2022 +0900

    fix(trait): disable NodePort by default for Service trait
    
    Fix #3253
---
 docs/modules/traits/pages/service.adoc | 2 +-
 pkg/trait/service.go                   | 4 ++--
 pkg/trait/service_test.go              | 8 +++++---
 resources/traits.yaml                  | 2 +-
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/docs/modules/traits/pages/service.adoc b/docs/modules/traits/pages/service.adoc
index 7e474ad91..b79dcc728 100755
--- a/docs/modules/traits/pages/service.adoc
+++ b/docs/modules/traits/pages/service.adoc
@@ -34,7 +34,7 @@ The following configuration options are available:
 
 | service.node-port
 | bool
-| Enable Service to be exposed as NodePort
+| Enable Service to be exposed as NodePort (default `false`).
 
 |===
 
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index 5590a3581..a070c8160 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -36,7 +36,7 @@ type serviceTrait struct {
 	BaseTrait `property:",squash"`
 	// To automatically detect from the code if a Service needs to be created.
 	Auto *bool `property:"auto" json:"auto,omitempty"`
-	// Enable Service to be exposed as NodePort
+	// Enable Service to be exposed as NodePort (default `false`).
 	NodePort *bool `property:"node-port" json:"nodePort,omitempty"`
 }
 
@@ -105,7 +105,7 @@ func (t *serviceTrait) Apply(e *Environment) error {
 	if svc == nil {
 		svc = getServiceFor(e)
 
-		if IsNilOrTrue(t.NodePort) {
+		if IsTrue(t.NodePort) {
 			svc.Spec.Type = corev1.ServiceTypeNodePort
 		}
 	}
diff --git a/pkg/trait/service_test.go b/pkg/trait/service_test.go
index aea727905..f97d6bc2c 100644
--- a/pkg/trait/service_test.go
+++ b/pkg/trait/service_test.go
@@ -125,6 +125,8 @@ func TestServiceWithDefaults(t *testing.T) {
 	assert.Len(t, d.Spec.Template.Spec.Containers[0].Ports, 1)
 	assert.Equal(t, int32(8080), d.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort)
 	assert.Equal(t, "http", d.Spec.Template.Spec.Containers[0].Ports[0].Name)
+
+	assert.Empty(t, s.Spec.Type) // empty means ClusterIP
 }
 
 func TestService(t *testing.T) {
@@ -329,9 +331,9 @@ func TestServiceWithNodePort(t *testing.T) {
 				},
 				Traits: map[string]v1.TraitSpec{
 					"service": test.TraitSpecFromMap(t, map[string]interface{}{
-						"enabled":   true,
-						"auto":      false,
-						"node-port": true,
+						"enabled":  true,
+						"auto":     false,
+						"nodePort": true,
 					}),
 				},
 			},
diff --git a/resources/traits.yaml b/resources/traits.yaml
index 0b585671d..8317239b5 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -1144,7 +1144,7 @@ traits:
     description: To automatically detect from the code if a Service needs to be created.
   - name: node-port
     type: bool
-    description: Enable Service to be exposed as NodePort
+    description: Enable Service to be exposed as NodePort (default `false`).
 - name: 3scale
   platform: false
   profiles: