From cf820b9f5a4582931e3eaa3005e2dad2257b1679 Mon Sep 17 00:00:00 2001 From: Huabing Zhao Date: Thu, 21 Nov 2024 09:35:04 +0000 Subject: [PATCH] fix 503 error caused by outdated endpooints Signed-off-by: Huabing Zhao --- internal/provider/kubernetes/controller.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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) + } + } } } }