From ce265c73b33fb6501f808ee206a435b323f5d6cd Mon Sep 17 00:00:00 2001 From: bitliu Date: Wed, 13 Dec 2023 20:46:40 +0800 Subject: [PATCH] fix: mergeGateways panics when restarting control plane Signed-off-by: bitliu --- internal/provider/kubernetes/predicates.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/provider/kubernetes/predicates.go b/internal/provider/kubernetes/predicates.go index 9a98bff1035..0ffcfc369a4 100644 --- a/internal/provider/kubernetes/predicates.go +++ b/internal/provider/kubernetes/predicates.go @@ -180,10 +180,13 @@ func (r *gatewayAPIReconciler) validateServiceForReconcile(obj client.Object) bo gclass, ok := labels[gatewayapi.OwningGatewayClassLabel] if ok { res, _ := r.resources.GatewayAPIResources.Load(gclass) - for _, gw := range res.Gateways { - gw := gw - r.statusUpdateForGateway(ctx, gw) + if res != nil && len(res.Gateways) > 0 { + for _, gw := range res.Gateways { + gw := gw + r.statusUpdateForGateway(ctx, gw) + } } + return false } @@ -313,9 +316,11 @@ func (r *gatewayAPIReconciler) validateDeploymentForReconcile(obj client.Object) gclass, ok := labels[gatewayapi.OwningGatewayClassLabel] if ok { res, _ := r.resources.GatewayAPIResources.Load(gclass) - for _, gtw := range res.Gateways { - gtw := gtw - r.statusUpdateForGateway(ctx, gtw) + if res != nil && len(res.Gateways) > 0 { + for _, gw := range res.Gateways { + gw := gw + r.statusUpdateForGateway(ctx, gw) + } } return false }