You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/08/11 14:29:53 UTC
[camel-k] 01/03: fix(trait): disable NodePort by default for Service trait
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch release-1.8.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 0a921c4bf81f2074c9c5ce5ae1afd982e07093de
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 9b6b6c5f0..9f362bb94 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 09dfeccf4..645d8a4ca 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -1143,7 +1143,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: