From 7bc30dbd61c9c39d2cfb403533d58c91eeafb496 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 2a1a4193641..8b6e9166c6b 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -67,14 +67,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) + } } } }