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

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

commit f3eba62e65e6fadacd5ed1d82afa5e04776f0849
Author: Tadayoshi Sato <sato.tadayo...@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:

Reply via email to