From 2b6d2a22729fd2f0d3a3ee500c1e3a1170a19350 Mon Sep 17 00:00:00 2001 From: Benjamin Alpert Date: Thu, 24 Jul 2025 16:39:20 +0200 Subject: [PATCH] filter out destinations for noderefs that are already tracked continue the outer for loop instead --- apinetlet/controllers/loadbalancer_controller.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apinetlet/controllers/loadbalancer_controller.go b/apinetlet/controllers/loadbalancer_controller.go index 5fd9c945..26e18507 100644 --- a/apinetlet/controllers/loadbalancer_controller.go +++ b/apinetlet/controllers/loadbalancer_controller.go @@ -329,14 +329,18 @@ func (r *LoadBalancerReconciler) applyAPINetLoadBalancer(ctx context.Context, lo if r.IsNodeAffinityAware { if len(apiNetDestinations) > 0 { + uniqueDsts := make(map[string]apinetv1alpha1.LoadBalancerDestination) + for _, dst := range apiNetDestinations { + uniqueDsts[dst.TargetRef.NodeRef.Name] = dst + } + nodeSelector := apinetv1alpha1ac.NodeSelector() - for i := range apiNetDestinations { - if apiNetDestinations[i].TargetRef != nil { - apiNetDestinationName := apiNetDestinations[i].TargetRef.NodeRef.Name + for dstName, dst := range uniqueDsts { + if dst.TargetRef != nil { nodeSelector.WithNodeSelectorTerms(apinetv1alpha1ac.NodeSelectorTerm().WithMatchFields(apinetv1alpha1ac.NodeSelectorRequirement(). WithKey("metadata.name"). WithOperator(apinetv1alpha1.NodeSelectorOpIn). - WithValues([]string{apiNetDestinationName}...), + WithValues([]string{dstName}...), )) } }