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