This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch 1070/provide-service-type in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit c4a4c40ab63d156883d99fda69fc6700ef235bd1 Author: Nicolas Filotto <[email protected]> AuthorDate: Wed Sep 7 16:49:35 2022 +0200 feat(trait): Provide the service type from the trait configuration --- .../duck/client/internalclientset/fake/register.go | 14 ++++---- .../client/internalclientset/scheme/register.go | 14 ++++---- .../camel.apache.org_integrationplatforms.yaml | 16 ++++++--- .../crd/bases/camel.apache.org_integrations.yaml | 8 +++-- .../bases/camel.apache.org_kameletbindings.yaml | 8 +++-- docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 18 ++++++++++ docs/modules/traits/pages/service.adoc | 5 +++ e2e/global/common/traits/service_test.go | 42 ++++++++++++++++++++++ helm/camel-k/crds/crd-integration-platform.yaml | 16 ++++++--- helm/camel-k/crds/crd-integration.yaml | 8 +++-- helm/camel-k/crds/crd-kamelet-binding.yaml | 8 +++-- pkg/apis/camel/v1/trait/service.go | 20 +++++++++++ pkg/apis/camel/v1/trait/zz_generated.deepcopy.go | 5 +++ .../camel/clientset/versioned/fake/register.go | 14 ++++---- .../camel/clientset/versioned/scheme/register.go | 14 ++++---- pkg/resources/resources.go | 16 ++++----- pkg/trait/service.go | 21 +++++++++-- resources/traits.yaml | 7 +++- 18 files changed, 198 insertions(+), 56 deletions(-) diff --git a/addons/strimzi/duck/client/internalclientset/fake/register.go b/addons/strimzi/duck/client/internalclientset/fake/register.go index b03a9f805..04aa54821 100644 --- a/addons/strimzi/duck/client/internalclientset/fake/register.go +++ b/addons/strimzi/duck/client/internalclientset/fake/register.go @@ -38,14 +38,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/addons/strimzi/duck/client/internalclientset/scheme/register.go b/addons/strimzi/duck/client/internalclientset/scheme/register.go index bb376affd..7c58dd36c 100644 --- a/addons/strimzi/duck/client/internalclientset/scheme/register.go +++ b/addons/strimzi/duck/client/internalclientset/scheme/register.go @@ -38,14 +38,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml index f01c288f1..89263abb4 100644 --- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -1588,9 +1588,13 @@ spec: traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort (default - `false`). + description: 'Enable Service to be exposed as NodePort (default + `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait @@ -3222,9 +3226,13 @@ spec: traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort (default - `false`). + description: 'Enable Service to be exposed as NodePort (default + `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml index 3a4f9bac0..9b095aa61 100644 --- a/config/crd/bases/camel.apache.org_integrations.yaml +++ b/config/crd/bases/camel.apache.org_integrations.yaml @@ -7279,9 +7279,13 @@ spec: traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort (default - `false`). + description: 'Enable Service to be exposed as NodePort (default + `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml index 37fe2cb1c..0a0b2b700 100644 --- a/config/crd/bases/camel.apache.org_kameletbindings.yaml +++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml @@ -7579,9 +7579,13 @@ spec: All traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort - (default `false`). + description: 'Enable Service to be exposed as NodePort + (default `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index 4aef3677f..c4dd65e87 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -5739,10 +5739,28 @@ bool Enable Service to be exposed as NodePort (default `false`). +Deprecated: Use service type instead + +|`type` + +*xref:#_camel_apache_org_v1_trait_ServiceType[ServiceType]* +| + + +The type of service to be used, either 'ClusterIP', 'NodePort' or 'LoadBalancer' (default `ClusterIP`) |=== +[#_camel_apache_org_v1_trait_ServiceType] +=== ServiceType(`string` alias) + +*Appears on:* + +* <<#_camel_apache_org_v1_trait_ServiceTrait, ServiceTrait>> + + + + [#_camel_apache_org_v1_trait_TolerationTrait] === TolerationTrait diff --git a/docs/modules/traits/pages/service.adoc b/docs/modules/traits/pages/service.adoc index b79dcc728..1afcfa5b7 100755 --- a/docs/modules/traits/pages/service.adoc +++ b/docs/modules/traits/pages/service.adoc @@ -35,6 +35,11 @@ The following configuration options are available: | service.node-port | bool | Enable Service to be exposed as NodePort (default `false`). +Deprecated: Use service type instead + +| service.type +| github.com/apache/camel-k/pkg/apis/camel/v1/trait.ServiceType +| The type of service to be used, either 'ClusterIP', 'NodePort' or 'LoadBalancer' (default `ClusterIP`) |=== diff --git a/e2e/global/common/traits/service_test.go b/e2e/global/common/traits/service_test.go index 12ae21a56..c98f45d4f 100644 --- a/e2e/global/common/traits/service_test.go +++ b/e2e/global/common/traits/service_test.go @@ -65,5 +65,47 @@ func TestServiceTrait(t *testing.T) { Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) }) + + t.Run("NodePort service from Type", func(t *testing.T) { + Expect(KamelRunWithID(operatorID, ns, "files/PlatformHttpServer.java", + "-t", "service.type=NodePort").Execute()).To(Succeed()) + Eventually(IntegrationPodPhase(ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + // + // Service names can vary with the ExternalName Service + // sometimes being created first and being given the root name + // + Eventually(ServicesByType(ns, corev1.ServiceTypeNodePort), TestTimeoutLong).ShouldNot(BeEmpty()) + + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) + }) + + t.Run("ClusterIP service from Type", func(t *testing.T) { + Expect(KamelRunWithID(operatorID, ns, "files/PlatformHttpServer.java", + "-t", "service.type=ClusterIP").Execute()).To(Succeed()) + Eventually(IntegrationPodPhase(ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + // + // Service names can vary with the ExternalName Service + // sometimes being created first and being given the root name + // + Eventually(ServicesByType(ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) + + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) + }) + + t.Run("LoadBalancer service from Type", func(t *testing.T) { + Expect(KamelRunWithID(operatorID, ns, "files/PlatformHttpServer.java", + "-t", "service.type=LoadBalancer").Execute()).To(Succeed()) + Eventually(IntegrationPodPhase(ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + // + // Service names can vary with the ExternalName Service + // sometimes being created first and being given the root name + // + Eventually(ServicesByType(ns, corev1.ServiceTypeLoadBalancer), TestTimeoutLong).ShouldNot(BeEmpty()) + + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) + }) }) } diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml index f01c288f1..89263abb4 100644 --- a/helm/camel-k/crds/crd-integration-platform.yaml +++ b/helm/camel-k/crds/crd-integration-platform.yaml @@ -1588,9 +1588,13 @@ spec: traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort (default - `false`). + description: 'Enable Service to be exposed as NodePort (default + `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait @@ -3222,9 +3226,13 @@ spec: traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort (default - `false`). + description: 'Enable Service to be exposed as NodePort (default + `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml index 3a4f9bac0..9b095aa61 100644 --- a/helm/camel-k/crds/crd-integration.yaml +++ b/helm/camel-k/crds/crd-integration.yaml @@ -7279,9 +7279,13 @@ spec: traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort (default - `false`). + description: 'Enable Service to be exposed as NodePort (default + `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml index 37fe2cb1c..0a0b2b700 100644 --- a/helm/camel-k/crds/crd-kamelet-binding.yaml +++ b/helm/camel-k/crds/crd-kamelet-binding.yaml @@ -7579,9 +7579,13 @@ spec: All traits share this common property. type: boolean nodePort: - description: Enable Service to be exposed as NodePort - (default `false`). + description: 'Enable Service to be exposed as NodePort + (default `false`). Deprecated: Use service type instead' type: boolean + type: + description: The type of service to be used, either 'ClusterIP', + 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + type: string type: object service-binding: description: The configuration of Service Binding trait diff --git a/pkg/apis/camel/v1/trait/service.go b/pkg/apis/camel/v1/trait/service.go index 83feadd2c..ab93bd28a 100644 --- a/pkg/apis/camel/v1/trait/service.go +++ b/pkg/apis/camel/v1/trait/service.go @@ -28,5 +28,25 @@ type ServiceTrait struct { // 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 (default `false`). + // Deprecated: Use service type instead NodePort *bool `property:"node-port" json:"nodePort,omitempty"` + // The type of service to be used, either 'ClusterIP', 'NodePort' or 'LoadBalancer' (default `ClusterIP`) + Type *ServiceType `property:"type" json:"type,omitempty"` } + +type ServiceType string + +const ( + // ServiceTypeClusterIP means a service will only be accessible inside the + // cluster, via the cluster IP. + ServiceTypeClusterIP ServiceType = "ClusterIP" + + // ServiceTypeNodePort means a service will be exposed on one port of + // every node, in addition to 'ClusterIP' type. + ServiceTypeNodePort ServiceType = "NodePort" + + // ServiceTypeLoadBalancer means a service will be exposed via an + // external load balancer (if the cloud provider supports it), in addition + // to 'NodePort' type. + ServiceTypeLoadBalancer ServiceType = "LoadBalancer" +) diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go index cab7a094d..f64b62a03 100644 --- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go @@ -942,6 +942,11 @@ func (in *ServiceTrait) DeepCopyInto(out *ServiceTrait) { *out = new(bool) **out = **in } + if in.Type != nil { + in, out := &in.Type, &out.Type + *out = new(ServiceType) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTrait. diff --git a/pkg/client/camel/clientset/versioned/fake/register.go b/pkg/client/camel/clientset/versioned/fake/register.go index 449936a90..327b4c8f0 100644 --- a/pkg/client/camel/clientset/versioned/fake/register.go +++ b/pkg/client/camel/clientset/versioned/fake/register.go @@ -40,14 +40,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/client/camel/clientset/versioned/scheme/register.go b/pkg/client/camel/clientset/versioned/scheme/register.go index 6c3443318..40ca6f0dc 100644 --- a/pkg/client/camel/clientset/versioned/scheme/register.go +++ b/pkg/client/camel/clientset/versioned/scheme/register.go @@ -40,14 +40,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go index 671b8b9f7..c0e6ad41a 100644 --- a/pkg/resources/resources.go +++ b/pkg/resources/resources.go @@ -138,23 +138,23 @@ var assets = func() http.FileSystem { "/crd/bases/camel.apache.org_integrationplatforms.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_integrationplatforms.yaml", modTime: time.Time{}, - uncompressedSize: 177901, + uncompressedSize: 178441, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\xdb\x36\xb6\x30\x8e\xff\x9e\xbf\x02\xe3\xce\x9d\x38\x19\x49\x4e\xba\xb7\xbb\xbd\x7e\xa6\xf3\x3c\xae\x93\xb6\x6e\xe2\xd8\xd7\x76\x72\xef\x4e\xdb\xa9\x20\xf2\x48\x42\x4c\x02\x5c\x00\x94\xad\x7e\xf7\xfb\xbf\x7f\x06\x07\x00\x49\x49\x24\x48\x49\x7e\x6b\x23\x76\x66\x37\xb6\x09\xf0\xe0\xe0\xe0\xbc\xe1\xbc\x7c\x45\xfa\x77\xf7\x3c\xfb\x8a\xbc\x67\x11\x70\x05\x31\xd1\x82\xe8\x29\x90\xa3\x8c\x46\x53\x20\x97\x62\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\xdb\x36\xb6\x30\x8e\xff\x9e\xbf\x02\xe3\xce\x1d\x3b\x19\x49\x4e\xba\xb7\xbb\xbd\x7e\xa6\xf3\x3c\xae\x93\xb6\x6e\xe2\xd8\xd7\x76\x72\xef\x4e\xdb\xa9\x20\xf2\x48\x42\x4c\x02\x5c\x00\x94\xa3\x7e\xf7\xfb\xbf\x7f\x06\x07\x00\x49\x49\x24\x48\x49\x7e\x6b\x23\x76\x66\x37\xb6\x09\xf0\xe0\xe0\xe0\xbc\xe1\xbc\x7c\x45\xfa\x77\xf7\x3c\xfb\x8a\xbc\x63\x11\x70\x05\x31\xd1\x82\xe8\x29\x90\xe3\x8c\x46\x53\x20\x57\x62\x [...] }, "/crd/bases/camel.apache.org_integrations.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_integrations.yaml", modTime: time.Time{}, - uncompressedSize: 487316, + uncompressedSize: 487586, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\x96\x38\x0c\xff\xef\x4f\x81\x72\x52\x3f\x49\x1b\x91\xb2\x33\xb3\x53\x3b\x7e\xa7\x36\xa5\x91\xe4\x44\x6f\x6c\x99\x65\x29\xc9\x2f\xe5\x64\x13\xb0\x1b\x24\xb1\x6a\x02\x3d\x00\x9a\x12\xe7\xc9\xf3\xdd\x9f\xc2\x01\xd0\x17\xde\xfa\xa0\x45\x3a\xce\x4c\x63\xaa\x32\x26\xc5\x3e\x8d\xcb\xc1\xb9\x5f\x3e\x23\x83\xfd\x8d\x67\x9f\x91\x37\x3c\x61\x42\xb3\x94\x18\x49\xcc\x8c\x91\xf3\x9c\x26\x33\x46\x6e\xe5\xc4\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\x96\x38\x0c\xff\xef\x4f\x81\x72\x52\x3f\x49\x1b\x91\xb2\x33\xb3\x53\x3b\x7e\xa7\x36\xa5\x91\xe4\x44\x6f\x6c\x99\x65\x29\xc9\x2f\xe5\x64\x13\xb0\x1b\x24\xb1\x6a\x02\x3d\x00\x9a\x12\xe7\xc9\xf3\xdd\x9f\xc2\x01\xd0\x17\xde\xfa\xa0\x45\x3a\xce\x4c\x63\xaa\x32\x26\xc5\x3e\x8d\xcb\xc1\xb9\x5f\x3e\x23\x83\xfd\x8d\x67\x9f\x91\x37\x3c\x61\x42\xb3\x94\x18\x49\xcc\x8c\x91\xf3\x9c\x26\x33\x46\x6e\xe5\xc4\x [...] }, "/crd/bases/camel.apache.org_kameletbindings.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_kameletbindings.yaml", modTime: time.Time{}, - uncompressedSize: 561190, + uncompressedSize: 561476, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\xb6\x28\x8a\xff\x9f\x4f\x81\x72\x52\x47\xd2\x8e\x48\xd9\x99\x47\xed\xf1\x6f\xea\xa4\xb4\x65\x39\xd1\x2f\xb1\xcc\xb2\x94\xe4\xa4\x9c\xec\x04\xec\x06\x49\x1c\x35\x81\xde\x00\x9a\x12\xe7\xe6\x7e\xf7\x5b\x58\x00\xba\xd1\x7c\x09\xab\x29\x69\xe4\x99\xc6\x54\x65\x4c\x8a\xbd\x1a\x8f\x85\xf5\x7e\x7c\x4e\x06\x0f\x37\x3e\xfb\x9c\x7c\xcf\x33\x26\x34\xcb\x89\x91\xc4\xcc\x18\x39\x2d\x69\x36\x63\xe4\x4a\x4e\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\xb6\x28\x8a\xff\x9f\x4f\x81\x72\x52\x47\xd2\x8e\x48\xd9\x99\x47\xed\xf1\x6f\xea\xa4\xb4\x65\x39\xd1\x2f\xb1\xcc\xb2\x94\xe4\xa4\x9c\xec\x04\xec\x06\x49\x1c\x35\x81\xde\x00\x9a\x12\xe7\xe6\x7e\xf7\x5b\x58\x00\xba\xd1\x7c\x09\xab\x29\x69\xe4\x99\xc6\x54\x65\x4c\x8a\xbd\x1a\x8f\x85\xf5\x7e\x7c\x4e\x06\x0f\x37\x3e\xfb\x9c\x7c\xcf\x33\x26\x34\xcb\x89\x91\xc4\xcc\x18\x39\x2d\x69\x36\x63\xe4\x4a\x4e\x [...] }, "/crd/bases/camel.apache.org_kamelets.yaml": &vfsgen۰CompressedFileInfo{ name: "camel.apache.org_kamelets.yaml", @@ -611,9 +611,9 @@ var assets = func() http.FileSystem { "/traits.yaml": &vfsgen۰CompressedFileInfo{ name: "traits.yaml", modTime: time.Time{}, - uncompressedSize: 53036, + uncompressedSize: 53294, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\xb9\xb5\x20\xfe\xff\x7c\x0a\x94\xee\xef\x96\x25\x17\x49\x79\x26\x77\x72\xe7\xa7\xdd\xb9\x59\x8d\xed\x49\x34\xe3\x87\xd6\xf2\x4c\x6e\xca\xeb\x0a\xc1\x6e\x90\x84\xd9\x04\x3a\x00\x5a\x32\xb3\xd9\xef\xbe\x85\xf3\x00\xd0\x64\x4b\xa2\x6c\x6b\x36\xda\xda\x4c\x55\x2c\x92\xdd\xc0\xc1\xc1\x39\x07\xe7\x8d\xe0\xa4\x0e\xfe\xe4\xab\xb1\x30\x72\xad\x4e\xc4\xef\x7c\x25\x1b\xf5\x95\x10\x6d\x23\xc3\xdc\xba\xf5\x89\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x23\xb9\x91\x20\xfe\xff\x7c\x0a\x84\xf6\xb7\xa1\x47\x90\x54\xcf\x78\xc7\x3b\x3f\xdd\xcd\xfa\x34\xdd\x3d\xb6\x66\xfa\xa1\x6b\x69\xc6\xeb\xe8\xeb\x30\xc1\x2a\x90\x44\xb3\x0a\x28\x03\x28\xa9\xe9\xf3\x7d\xf7\x0b\x64\x26\x1e\x55\x2c\x8a\x54\xb7\x34\x67\x5d\x9c\x27\xc2\x2d\x92\x55\x40\x22\x91\x99\xc8\x37\x9c\xe1\xd2\xd9\xb3\xaf\xc6\x4c\xf1\x5a\x9c\xb1\xdf\xd9\x82\x57\xe2\x2b\xc6\x9a\x8a\xbb\xb9\x36\xf5\x19\x [...] }, } fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ diff --git a/pkg/trait/service.go b/pkg/trait/service.go index d4211fb39..eb46b5cb5 100644 --- a/pkg/trait/service.go +++ b/pkg/trait/service.go @@ -18,6 +18,8 @@ limitations under the License. package trait import ( + "fmt" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/pointer" @@ -90,7 +92,6 @@ func (t *serviceTrait) Configure(e *Environment) (bool, error) { return false, nil } } - return true, nil } @@ -100,9 +101,23 @@ func (t *serviceTrait) Apply(e *Environment) error { if svc == nil { svc = getServiceFor(e) - if pointer.BoolDeref(t.NodePort, false) { - svc.Spec.Type = corev1.ServiceTypeNodePort + var serviceType corev1.ServiceType + if t.Type != nil { + switch *t.Type { + case traitv1.ServiceTypeClusterIP: + serviceType = corev1.ServiceTypeClusterIP + case traitv1.ServiceTypeNodePort: + serviceType = corev1.ServiceTypeNodePort + case traitv1.ServiceTypeLoadBalancer: + serviceType = corev1.ServiceTypeLoadBalancer + default: + return fmt.Errorf("unsupported service type: %s", *t.Type) + } + } else if pointer.BoolDeref(t.NodePort, false) { + t.L.ForIntegration(e.Integration).Infof("Integration %s/%s should no more use the flag node-port as it is deprecated, use type instead", e.Integration.Namespace, e.Integration.Name) + serviceType = corev1.ServiceTypeNodePort } + svc.Spec.Type = serviceType } e.Resources.Add(svc) return nil diff --git a/resources/traits.yaml b/resources/traits.yaml index 2f52eb1dc..4269816f6 100755 --- a/resources/traits.yaml +++ b/resources/traits.yaml @@ -1183,7 +1183,12 @@ 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 (default `false`). + description: 'Enable Service to be exposed as NodePort (default `false`). Deprecated: + Use service type instead' + - name: type + type: github.com/apache/camel-k/pkg/apis/camel/v1/trait.ServiceType + description: The type of service to be used, either 'ClusterIP', 'NodePort' or + 'LoadBalancer' (default `ClusterIP`) - name: service-binding platform: false profiles:
