@@ -605,7 +605,6 @@ func (c *Controller) gcPortGroup() error {
605
605
klog .Info ("start to gc network policy" )
606
606
607
607
npNames := strset .New ()
608
- delPgNames := strset .New ()
609
608
610
609
if c .config .EnableNP {
611
610
nps , err := c .npsLister .List (labels .Everything ())
@@ -623,66 +622,53 @@ func (c *Controller) gcPortGroup() error {
623
622
624
623
npNames .Add (fmt .Sprintf ("%s/%s" , np .Namespace , npName ))
625
624
}
626
- }
627
-
628
- // append node port group to npNames to avoid gc node port group
629
- nodes , err := c .nodesLister .List (labels .Everything ())
630
- if err != nil {
631
- klog .Errorf ("failed to list nodes, %v" , err )
632
- return err
633
- }
634
-
635
- for _ , node := range nodes {
636
- npNames .Add (fmt .Sprintf ("%s/%s" , "node" , node .Name ))
637
- }
638
625
639
- // append overlay subnets port group to npNames to avoid gc distributed subnets port group
640
- subnets , err := c .subnetsLister .List (labels .Everything ())
641
- if err != nil {
642
- klog .Errorf ("failed to list subnets %v" , err )
643
- return err
644
- }
645
- for _ , subnet := range subnets {
646
- if subnet .Spec .Vpc != c .config .ClusterRouter || (subnet .Spec .Vlan != "" && ! subnet .Spec .LogicalGateway ) || subnet .Name == c .config .NodeSwitch || subnet .Spec .GatewayType != kubeovnv1 .GWDistributedType {
647
- continue
626
+ // append node port group to npNames to avoid gc node port group
627
+ nodes , err := c .nodesLister .List (labels .Everything ())
628
+ if err != nil {
629
+ klog .Errorf ("failed to list nodes, %v" , err )
630
+ return err
648
631
}
649
632
650
633
for _ , node := range nodes {
651
- npNames .Add (fmt .Sprintf ("%s/%s" , subnet . Name , node .Name ))
634
+ npNames .Add (fmt .Sprintf ("%s/%s" , "node" , node .Name ))
652
635
}
653
- }
654
636
655
- // list all np port groups which externalIDs[np]!=""
656
- pgs , err := c .OVNNbClient .ListPortGroups (map [string ]string {networkPolicyKey : "" })
657
- if err != nil {
658
- klog .Errorf ("list np port group: %v" , err )
659
- return err
660
- }
637
+ // append overlay subnets port group to npNames to avoid gc distributed subnets port group
638
+ subnets , err := c .subnetsLister .List (labels .Everything ())
639
+ if err != nil {
640
+ klog .Errorf ("failed to list subnets %v" , err )
641
+ return err
642
+ }
643
+ for _ , subnet := range subnets {
644
+ if subnet .Spec .Vpc != c .config .ClusterRouter || (subnet .Spec .Vlan != "" && ! subnet .Spec .LogicalGateway ) || subnet .Name == c .config .NodeSwitch || subnet .Spec .GatewayType != kubeovnv1 .GWDistributedType {
645
+ continue
646
+ }
661
647
662
- for _ , pg := range pgs {
663
- np := strings .Split (pg .ExternalIDs [networkPolicyKey ], "/" )
664
- if len (np ) != 2 {
665
- // not np port group
666
- continue
648
+ for _ , node := range nodes {
649
+ npNames .Add (fmt .Sprintf ("%s/%s" , subnet .Name , node .Name ))
650
+ }
667
651
}
668
- if ! npNames .Has (pg .ExternalIDs [networkPolicyKey ]) {
669
- klog .Infof ("gc port group '%s' network policy '%s'" , pg .Name , pg .ExternalIDs [networkPolicyKey ])
670
- delPgNames .Add (pg .Name )
671
- if c .config .EnableNP {
652
+
653
+ // list all np port groups which externalIDs[np]!=""
654
+ pgs , err := c .OVNNbClient .ListPortGroups (map [string ]string {networkPolicyKey : "" })
655
+ if err != nil {
656
+ klog .Errorf ("list np port group: %v" , err )
657
+ return err
658
+ }
659
+
660
+ for _ , pg := range pgs {
661
+ np := strings .Split (pg .ExternalIDs [networkPolicyKey ], "/" )
662
+ if len (np ) != 2 {
663
+ // not np port group
664
+ continue
665
+ }
666
+ if ! npNames .Has (pg .ExternalIDs [networkPolicyKey ]) {
667
+ klog .Infof ("gc port group '%s' network policy '%s'" , pg .Name , pg .ExternalIDs [networkPolicyKey ])
672
668
c .deleteNpQueue .Add (pg .ExternalIDs [networkPolicyKey ])
673
669
}
674
670
}
675
671
}
676
- // gc port group
677
- // the pgName in the network policy is generated differently from the node/subnet pgName
678
- // so processes port group gc separately
679
- // ensure that the port group can be correctly gc
680
- delPgNames .Each (func (item string ) bool {
681
- if err := c .OVNNbClient .DeletePortGroup (item ); err != nil {
682
- klog .Errorf ("failed to gc port group %s: %v" , item , err )
683
- }
684
- return true
685
- })
686
672
687
673
return nil
688
674
}
0 commit comments