This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 0fdfcaa8f feat(trait): service annotations
0fdfcaa8f is described below
commit 0fdfcaa8f6aa47e4a8fa8c6c8767aae721dccf21
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Wed Oct 23 21:45:45 2024 +0200
feat(trait): service annotations
Closes #5901
---
docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 7 ++
docs/modules/traits/pages/service.adoc | 4 ++
helm/camel-k/crds/camel-k-crds.yaml | 40 +++++++++++
pkg/apis/camel/v1/trait/service.go | 2 +
pkg/apis/camel/v1/trait/zz_generated.deepcopy.go | 7 ++
.../camel.apache.org_integrationplatforms.yaml | 10 +++
.../camel.apache.org_integrationprofiles.yaml | 10 +++
.../crd/bases/camel.apache.org_integrations.yaml | 10 +++
.../bases/camel.apache.org_kameletbindings.yaml | 5 ++
.../config/crd/bases/camel.apache.org_pipes.yaml | 5 ++
pkg/trait/service.go | 13 ++--
pkg/trait/service_test.go | 81 ++++++++++++++++++++++
12 files changed, 188 insertions(+), 6 deletions(-)
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index 4c2503277..6a58a7a56 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -8790,6 +8790,13 @@ Deprecated: Use service type instead.
The type of service to be used, either 'ClusterIP', 'NodePort' or
'LoadBalancer'.
+|`annotations` +
+map[string]string
+|
+
+
+The annotations added to the Service object.
+
|===
diff --git a/docs/modules/traits/pages/service.adoc
b/docs/modules/traits/pages/service.adoc
index 6208a346b..e66dbcca0 100755
--- a/docs/modules/traits/pages/service.adoc
+++ b/docs/modules/traits/pages/service.adoc
@@ -45,6 +45,10 @@ Deprecated: Use service type instead.
| github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait.ServiceType
| The type of service to be used, either 'ClusterIP', 'NodePort' or
'LoadBalancer'.
+| service.annotations
+| map[string]string
+| The annotations added to the Service object.
+
|===
// End of autogenerated code - DO NOT EDIT! (configuration)
diff --git a/helm/camel-k/crds/camel-k-crds.yaml
b/helm/camel-k/crds/camel-k-crds.yaml
index 12e238d8a..3bb34c12b 100644
--- a/helm/camel-k/crds/camel-k-crds.yaml
+++ b/helm/camel-k/crds/camel-k-crds.yaml
@@ -5212,6 +5212,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -7352,6 +7357,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -9395,6 +9405,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -11414,6 +11429,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -19474,6 +19494,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -21455,6 +21480,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -29591,6 +29621,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code
if
a Service needs to be created.
@@ -40517,6 +40552,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code
if
a Service needs to be created.
diff --git a/pkg/apis/camel/v1/trait/service.go
b/pkg/apis/camel/v1/trait/service.go
index 4452576d9..924fbcc14 100644
--- a/pkg/apis/camel/v1/trait/service.go
+++ b/pkg/apis/camel/v1/trait/service.go
@@ -35,6 +35,8 @@ type ServiceTrait struct {
// The type of service to be used, either 'ClusterIP', 'NodePort' or
'LoadBalancer'.
// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
Type *ServiceType `property:"type" json:"type,omitempty"`
+ // The annotations added to the Service object.
+ Annotations map[string]string `property:"annotations"
json:"annotations,omitempty"`
}
type ServiceType string
diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
index 42b190f70..36235e591 100644
--- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
@@ -1156,6 +1156,13 @@ func (in *ServiceTrait) DeepCopyInto(out *ServiceTrait) {
*out = new(ServiceType)
**out = **in
}
+ if in.Annotations != nil {
+ in, out := &in.Annotations, &out.Annotations
+ *out = make(map[string]string, len(*in))
+ for key, val := range *in {
+ (*out)[key] = val
+ }
+ }
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver,
creating a new ServiceTrait.
diff --git
a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 163232d42..dc2cb3a04 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -2054,6 +2054,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -4194,6 +4199,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
diff --git
a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
index fd964cb8e..748fba573 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml
@@ -1923,6 +1923,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -3942,6 +3947,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
index 520f496bc..fdf089424 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml
@@ -7943,6 +7943,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
@@ -9924,6 +9929,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code if
a Service
needs to be created.
diff --git
a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml
b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml
index 93ead8554..bafbf1080 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -8012,6 +8012,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code
if
a Service needs to be created.
diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
index 91af8ae44..5c0bacc7b 100644
--- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
+++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
@@ -8010,6 +8010,11 @@ spec:
service:
description: The configuration of Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: The annotations added to the Service
object.
+ type: object
auto:
description: To automatically detect from the code
if
a Service needs to be created.
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index 9cb3e8522..2c4282576 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -97,7 +97,7 @@ func (t *serviceTrait) Apply(e *Environment) error {
svc := e.Resources.GetServiceForIntegration(e.Integration)
// add a new service if not already created
if svc == nil {
- svc = getServiceFor(e)
+ svc = t.getServiceFor(e.Integration.Name,
e.Integration.Namespace)
var serviceType corev1.ServiceType
if t.Type != nil {
@@ -121,23 +121,24 @@ func (t *serviceTrait) Apply(e *Environment) error {
return nil
}
-func getServiceFor(e *Environment) *corev1.Service {
+func (t *serviceTrait) getServiceFor(itName, itNamespace string)
*corev1.Service {
return &corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
- Name: e.Integration.Name,
- Namespace: e.Integration.Namespace,
+ Name: itName,
+ Namespace: itNamespace,
Labels: map[string]string{
- v1.IntegrationLabel: e.Integration.Name,
+ v1.IntegrationLabel: itName,
},
+ Annotations: t.Annotations,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{},
Selector: map[string]string{
- v1.IntegrationLabel: e.Integration.Name,
+ v1.IntegrationLabel: itName,
},
},
}
diff --git a/pkg/trait/service_test.go b/pkg/trait/service_test.go
index 4d0f3f085..2d9ab2353 100644
--- a/pkg/trait/service_test.go
+++ b/pkg/trait/service_test.go
@@ -740,3 +740,84 @@ func TestServiceAutoConfiguration(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, ptr.To(true), traits.Service.Enabled)
}
+
+func TestServiceAnnotations(t *testing.T) {
+ catalog, err := camel.DefaultCatalog()
+ require.NoError(t, err)
+
+ client, _ := test.NewFakeClient()
+ traitCatalog := NewCatalog(nil)
+
+ compressedRoute, err :=
gzip.CompressBase64([]byte(`from("netty-http:test").log("hello")`))
+ require.NoError(t, err)
+
+ environment := Environment{
+ CamelCatalog: catalog,
+ Catalog: traitCatalog,
+ Client: client,
+ Integration: &v1.Integration{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: ServiceTestName,
+ Namespace: "ns",
+ },
+ Status: v1.IntegrationStatus{
+ Phase: v1.IntegrationPhaseDeploying,
+ },
+ Spec: v1.IntegrationSpec{
+ Profile: v1.TraitProfileKubernetes,
+ Sources: []v1.SourceSpec{
+ {
+ DataSpec: v1.DataSpec{
+ Name:
"routes.js",
+ Content:
string(compressedRoute),
+ Compression: true,
+ },
+ Language: v1.LanguageJavaScript,
+ },
+ },
+ Traits: v1.Traits{
+ Service: &traitv1.ServiceTrait{
+ Auto: ptr.To(true),
+ Annotations: map[string]string{
+ "annotation-1":
"value-1",
+ "annotation-2":
"value-2",
+ },
+ },
+ },
+ },
+ },
+ IntegrationKit: &v1.IntegrationKit{
+ Status: v1.IntegrationKitStatus{
+ Phase: v1.IntegrationKitPhaseReady,
+ },
+ },
+ Platform: &v1.IntegrationPlatform{
+ Spec: v1.IntegrationPlatformSpec{
+ Cluster: v1.IntegrationPlatformClusterOpenShift,
+ Build: v1.IntegrationPlatformBuildSpec{
+ PublishStrategy:
v1.IntegrationPlatformBuildPublishStrategyS2I,
+ Registry:
v1.RegistrySpec{Address: "registry"},
+ RuntimeVersion:
catalog.Runtime.Version,
+ },
+ },
+ Status: v1.IntegrationPlatformStatus{
+ Phase: v1.IntegrationPlatformPhaseReady,
+ },
+ },
+ EnvVars: make([]corev1.EnvVar, 0),
+ ExecutedTraits: make([]Trait, 0),
+ Resources: kubernetes.NewCollection(),
+ }
+ environment.Platform.ResyncStatusFullConfig()
+
+ _, _, err = traitCatalog.apply(&environment)
+
+ require.NoError(t, err)
+ s := environment.Resources.GetService(func(service *corev1.Service)
bool {
+ return service.Name == ServiceTestName
+ })
+ assert.NotNil(t, s)
+ assert.NotNil(t, s.Annotations)
+ assert.Equal(t, "value-1", s.Annotations["annotation-1"])
+ assert.Equal(t, "value-2", s.Annotations["annotation-2"])
+}