From ce3c8c519592c0d9f5dc7feba97916f819576568 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 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index 28a0eafaa77..930d2885735 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -454,12 +454,22 @@ 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 { + updated := gwcResource.EndpointSlices + for i, es := range gwcResource.EndpointSlices { + if es.Name == endpointSlice.Name && es.Namespace == endpointSlice.Namespace { + updated = append(updated[:i], updated[i+1:]...) + updated = append(updated, &endpointSlice) + break + } + } + gwcResource.EndpointSlices = updated } } }