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 <arthur@cri.epita.fr>
This commit is contained in:
Arthur Outhenin-Chalandre 2025-03-26 13:30:25 +01:00 committed by GitHub
parent 49f47d9503
commit edbcb64886
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -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],

View File

@ -50,6 +50,7 @@ func ToServiceImport(obj meta.Object) (meta.Object, error) {
copy(s.Ports, svc.Spec.Ports)
}
*svc = mcs.ServiceImport{}
return s, nil
}