From 3ee7f4d42d7c20c0a00db6c4c2f2fe2986d9fb02 Mon Sep 17 00:00:00 2001 From: MenD32 Date: Thu, 12 Sep 2024 22:22:43 +0300 Subject: [PATCH] changed labels and annotations logic to merge Signed-off-by: MenD32 --- controllers/eventsource/resource.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/controllers/eventsource/resource.go b/controllers/eventsource/resource.go index 3a92d4ce22..2c36b2b5cd 100644 --- a/controllers/eventsource/resource.go +++ b/controllers/eventsource/resource.go @@ -389,7 +389,6 @@ func buildService(args *AdaptorArgs) (*corev1.Service, error) { ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-eventsource-svc", eventSource.Name), Namespace: eventSource.Namespace, - Labels: mergeLabels(args.EventSource.Labels, args.Labels), }, Spec: corev1.ServiceSpec{ Ports: ports, @@ -399,15 +398,21 @@ func buildService(args *AdaptorArgs) (*corev1.Service, error) { }, } + labels := mergeLabels(args.EventSource.Labels, args.Labels) + annotations := make(map[string]string) + if args.EventSource.Spec.Service.Metadata != nil { if args.EventSource.Spec.Service.Metadata.Labels != nil { - svc.ObjectMeta.SetLabels(args.EventSource.Spec.Service.Metadata.Labels) + labels = mergeLabels(labels, args.EventSource.Spec.Service.Metadata.Labels) } if args.EventSource.Spec.Service.Metadata.Annotations != nil { - svc.ObjectMeta.SetAnnotations(args.EventSource.Spec.Service.Metadata.Annotations) + annotations = mergeLabels(annotations, args.EventSource.Spec.Service.Metadata.Annotations) } } + svc.ObjectMeta.SetLabels(labels) + svc.ObjectMeta.SetAnnotations(annotations) + if err := controllerscommon.SetObjectMeta(eventSource, svc, v1alpha1.SchemaGroupVersionKind); err != nil { return nil, err }