@@ -1496,20 +1496,10 @@ func (bnc *BaseNetworkController) peerNamespaceUpdate(np *networkPolicy, gp *gre
14961496 return err
14971497}
14981498
1499- // requeuePeerNamespaces enqueues the namespace into network policy peer namespace
1499+ // requeuePeerNamespace enqueues the namespace into network policy peer namespace
15001500// retry framework object(s) which need to be retried immediately with add event.
1501- func (bnc * BaseNetworkController ) requeuePeerNamespaces ( namespaces [] string ) error {
1501+ func (bnc * BaseNetworkController ) requeuePeerNamespace ( namespace * corev1. Namespace ) error {
15021502 var errors []error
1503- var peerNamespaces []* corev1.Namespace
1504- for _ , ns := range namespaces {
1505- namespace , err := bnc .watchFactory .GetNamespace (ns )
1506- if err != nil {
1507- errors = append (errors , fmt .Errorf ("failed to retrieve namespace %s for reconciling network %s: %w" ,
1508- ns , bnc .GetNetworkName (), err ))
1509- continue
1510- }
1511- peerNamespaces = append (peerNamespaces , namespace )
1512- }
15131503 npKeys := bnc .networkPolicies .GetKeys ()
15141504 for _ , npKey := range npKeys {
15151505 err := bnc .networkPolicies .DoWithLock (npKey , func (npKey string ) error {
@@ -1519,26 +1509,23 @@ func (bnc *BaseNetworkController) requeuePeerNamespaces(namespaces []string) err
15191509 }
15201510 np .RLock ()
15211511 defer np .RUnlock ()
1512+ if np .deleted {
1513+ return nil
1514+ }
15221515 var errors []error
15231516 for _ , reconcilePeerNamespace := range np .reconcilePeerNamespaces {
1524- namespaceAdded := false
1525- for _ , namespace := range peerNamespaces {
1526- // Filter out namespace when it's labels not matching with network policy peer namespace
1527- // selector.
1528- if ! reconcilePeerNamespace .handler .FilterFunc (namespace ) {
1529- continue
1530- }
1531- err := reconcilePeerNamespace .retryFramework .AddRetryObjWithAddNoBackoff (namespace )
1532- if err != nil {
1533- errors = append (errors , fmt .Errorf ("failed to retry peer namespace %s for network policy %s on network %s: %w" ,
1534- namespace .Name , npKey , bnc .GetNetworkName (), err ))
1535- continue
1536- }
1537- namespaceAdded = true
1517+ // Filter out namespace when it's labels not matching with network policy peer namespace
1518+ // selector.
1519+ if ! reconcilePeerNamespace .handler .FilterFunc (namespace ) {
1520+ continue
15381521 }
1539- if namespaceAdded {
1540- reconcilePeerNamespace .retryFramework .RequestRetryObjs ()
1522+ err := reconcilePeerNamespace .retryFramework .AddRetryObjWithAddNoBackoff (namespace )
1523+ if err != nil {
1524+ errors = append (errors , fmt .Errorf ("failed to retry peer namespace %s for network policy %s on network %s: %w" ,
1525+ namespace .Name , npKey , bnc .GetNetworkName (), err ))
1526+ continue
15411527 }
1528+ reconcilePeerNamespace .retryFramework .RequestRetryObjs ()
15421529 }
15431530 return utilerrors .Join (errors ... )
15441531 })
@@ -1587,11 +1574,13 @@ func (bnc *BaseNetworkController) addPeerNamespaceHandler(
15871574 // a new peer namespace is newly created later under UDN network, it gets reconciled and
15881575 // address set is created for the namespace. so we must reconcile it for network policy
15891576 // as well to update gress policy ACL with matching peer namespace address set.
1590- np .Lock ()
1591- np .reconcilePeerNamespaces = append (np .reconcilePeerNamespaces ,
1592- & peerNamespacesRetry {retryFramework : retryPeerNamespaces ,
1593- handler : namespaceHandler })
1594- np .Unlock ()
1577+ if bnc .IsPrimaryNetwork () {
1578+ np .Lock ()
1579+ np .reconcilePeerNamespaces = append (np .reconcilePeerNamespaces ,
1580+ & peerNamespacesRetry {retryFramework : retryPeerNamespaces ,
1581+ handler : namespaceHandler })
1582+ np .Unlock ()
1583+ }
15951584
15961585 return nil
15971586}
0 commit comments