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
commit c6b3ba1791502054119cfc66fb28a26387a5c432 Author: Pasquale Congiusti <[email protected]> AuthorDate: Fri Oct 25 07:41:07 2024 +0200 feat(trait): service label --- pkg/apis/camel/v1/trait/service.go | 2 ++ pkg/trait/service.go | 14 +++++++++----- pkg/trait/service_test.go | 12 +++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/apis/camel/v1/trait/service.go b/pkg/apis/camel/v1/trait/service.go index 924fbcc14..ed3d53136 100644 --- a/pkg/apis/camel/v1/trait/service.go +++ b/pkg/apis/camel/v1/trait/service.go @@ -37,6 +37,8 @@ type ServiceTrait struct { Type *ServiceType `property:"type" json:"type,omitempty"` // The annotations added to the Service object. Annotations map[string]string `property:"annotations" json:"annotations,omitempty"` + // The labels added to the Service object. + Labels map[string]string `property:"labels" json:"labels,omitempty"` } type ServiceType string diff --git a/pkg/trait/service.go b/pkg/trait/service.go index 2c4282576..c531f8feb 100644 --- a/pkg/trait/service.go +++ b/pkg/trait/service.go @@ -122,17 +122,21 @@ func (t *serviceTrait) Apply(e *Environment) error { } func (t *serviceTrait) getServiceFor(itName, itNamespace string) *corev1.Service { + labels := map[string]string{ + v1.IntegrationLabel: itName, + } + for k, v := range t.Labels { + labels[k] = v + } return &corev1.Service{ TypeMeta: metav1.TypeMeta{ Kind: "Service", APIVersion: "v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: itName, - Namespace: itNamespace, - Labels: map[string]string{ - v1.IntegrationLabel: itName, - }, + Name: itName, + Namespace: itNamespace, + Labels: labels, Annotations: t.Annotations, }, Spec: corev1.ServiceSpec{ diff --git a/pkg/trait/service_test.go b/pkg/trait/service_test.go index 2d9ab2353..25c6935c7 100644 --- a/pkg/trait/service_test.go +++ b/pkg/trait/service_test.go @@ -741,7 +741,7 @@ func TestServiceAutoConfiguration(t *testing.T) { assert.Equal(t, ptr.To(true), traits.Service.Enabled) } -func TestServiceAnnotations(t *testing.T) { +func TestServiceAnnotationsAndLables(t *testing.T) { catalog, err := camel.DefaultCatalog() require.NoError(t, err) @@ -782,6 +782,10 @@ func TestServiceAnnotations(t *testing.T) { "annotation-1": "value-1", "annotation-2": "value-2", }, + Labels: map[string]string{ + "label-1": "v1", + "label-2": "v2", + }, }, }, }, @@ -818,6 +822,12 @@ func TestServiceAnnotations(t *testing.T) { }) assert.NotNil(t, s) assert.NotNil(t, s.Annotations) + assert.Len(t, s.Annotations, 2) assert.Equal(t, "value-1", s.Annotations["annotation-1"]) assert.Equal(t, "value-2", s.Annotations["annotation-2"]) + // There are other labels added by other traits + assert.Len(t, s.Labels, 5) + assert.Equal(t, "v1", s.Labels["label-1"]) + assert.Equal(t, "v2", s.Labels["label-2"]) + assert.Equal(t, ServiceTestName, s.Labels[v1.IntegrationLabel]) }
