From 26224c58dfc884f86c965990ea37c5e69144ff74 Mon Sep 17 00:00:00 2001 From: SKALA NETWORKS <127797154+SkalaNetworks@users.noreply.github.com> Date: Tue, 24 Dec 2024 04:21:14 +0100 Subject: [PATCH] fix(controller/subnet): controller crashes on subnets if gateway is unspecified and netpol are disabled (#4848) Signed-off-by: SkalaNetworks --- pkg/controller/subnet.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index 8de2b3bf6b6..81dd2c08a45 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -70,14 +70,16 @@ func (c *Controller) enqueueUpdateSubnet(oldObj, newObj interface{}) { return } - if newSubnet.Spec.Gateway != oldSubnet.Spec.Gateway || - newSubnet.Status.U2OInterconnectionIP != oldSubnet.Status.U2OInterconnectionIP { - policies, err := c.npsLister.List(labels.Everything()) - if err != nil { - klog.Errorf("failed to list network policies: %v", err) - } else { - for _, np := range policies { - c.enqueueAddNp(np) + // Trigger network policy refresh only if they are enabled, otherwise the lister will be nil + if c.npsLister != nil { + if newSubnet.Spec.Gateway != oldSubnet.Spec.Gateway || newSubnet.Status.U2OInterconnectionIP != oldSubnet.Status.U2OInterconnectionIP { + policies, err := c.npsLister.List(labels.Everything()) + if err != nil { + klog.Errorf("failed to list network policies: %v", err) + } else { + for _, np := range policies { + c.enqueueAddNp(np) + } } } }