diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index d40e1823e85..af8040df8bc 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -50,14 +50,16 @@ func (c *Controller) enqueueUpdateSubnet(oldObj, newObj interface{}) { newSubnet := newObj.(*kubeovnv1.Subnet) key := cache.MetaObjectToName(newSubnet).String() - 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) + } } } }