From edbcb64886f6ea1418db002e93ee5a2743ddcfc2 Mon Sep 17 00:00:00 2001 From: Arthur Outhenin-Chalandre Date: Wed, 26 Mar 2025 13:30:25 +0100 Subject: [PATCH] object: fix object cleanup (#27) This commit add object cleanup to be consistent with similar code in the kubernetes plugin. It also does a clone of the EndpointSlice labels so that it's not erased by the function `EndpointSliceToEndpoints` from the kubernetes plugin fixing an important bug in the multicluster code as it was previously not able to retrieve any labels which essentially prevented any interaction with headless services. Signed-off-by: Arthur Outhenin-Chalandre --- object/endpoint.go | 4 +++- object/serviceimport.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/object/endpoint.go b/object/endpoint.go index e747890..b7bb4cd 100644 --- a/object/endpoint.go +++ b/object/endpoint.go @@ -1,6 +1,8 @@ package object import ( + "maps" + "github.com/coredns/coredns/plugin/kubernetes/object" mcs "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" @@ -20,11 +22,11 @@ func EndpointsKey(name, namespace string) string { return name + "." + namespace // EndpointSliceToEndpoints converts a *discovery.EndpointSlice to a *Endpoints. func EndpointSliceToEndpoints(obj meta.Object) (meta.Object, error) { + labels := maps.Clone(obj.GetLabels()) ends, err := object.EndpointSliceToEndpoints(obj) if err != nil { return nil, err } - labels := obj.GetLabels() e := &Endpoints{ Endpoints: *ends.(*object.Endpoints), ClusterId: labels[mcs.LabelSourceCluster], diff --git a/object/serviceimport.go b/object/serviceimport.go index a08333b..738348a 100644 --- a/object/serviceimport.go +++ b/object/serviceimport.go @@ -50,6 +50,7 @@ func ToServiceImport(obj meta.Object) (meta.Object, error) { copy(s.Ports, svc.Spec.Ports) } + *svc = mcs.ServiceImport{} return s, nil }