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) + } } } }