diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index 28a0eafaa77..a0ece760968 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -454,12 +454,19 @@ func (r *gatewayAPIReconciler) processBackendRefs(ctx context.Context, gwcResour } else { for _, endpointSlice := range endpointSliceList.Items { key := utils.NamespacedName(&endpointSlice).String() + r.log.Info("added EndpointSlice to resource tree", + "namespace", endpointSlice.Namespace, + "name", endpointSlice.Name) if !resourceMappings.allAssociatedEndpointSlices.Has(key) { resourceMappings.allAssociatedEndpointSlices.Insert(key) - r.log.Info("added EndpointSlice to resource tree", - "namespace", endpointSlice.Namespace, - "name", endpointSlice.Name) gwcResource.EndpointSlices = append(gwcResource.EndpointSlices, &endpointSlice) + } else { + for i, es := range gwcResource.EndpointSlices { + if es.Name == endpointSlice.Name && es.Namespace == endpointSlice.Namespace { + gwcResource.EndpointSlices = append(gwcResource.EndpointSlices[:i], gwcResource.EndpointSlices[i+1:]...) + gwcResource.EndpointSlices = append(gwcResource.EndpointSlices, &endpointSlice) + } + } } } }