@@ -62,6 +62,40 @@ func (c *Controller) enqueueUpdateNp(oldObj, newObj interface{}) {
62
62
}
63
63
}
64
64
65
+ // for upgrading from v1.12.x to v1.13.x
66
+ func (c * Controller ) upgradeNetworkPoliciesForV1_13 () error {
67
+ // clear legacy acls in tier 0 for all network policies
68
+ // including ingress, egress and subnet gateway acls
69
+ nps , err := c .npsLister .NetworkPolicies (corev1 .NamespaceAll ).List (labels .Everything ())
70
+ if err != nil {
71
+ klog .Errorf ("failed to list network policies %v" , err )
72
+ return err
73
+ }
74
+
75
+ for _ , np := range nps {
76
+ npName := np .Name
77
+ nameArray := []rune (np .Name )
78
+ if ! unicode .IsLetter (nameArray [0 ]) {
79
+ npName = "np" + np .Name
80
+ }
81
+ pgName := strings .ReplaceAll (fmt .Sprintf ("%s.%s" , npName , np .Namespace ), "-" , "." )
82
+
83
+ if err = c .OVNNbClient .DeleteAcls (pgName , portGroupKey , "" , nil , util .DefaultACLTier ); err != nil {
84
+ klog .Errorf ("clear legacy network policy %s acls: %v" , pgName , err )
85
+ return err
86
+ }
87
+ }
88
+
89
+ return nil
90
+ }
91
+
92
+ func (c * Controller ) upgradeNetworkPolicies () error {
93
+ if err := c .upgradeNetworkPoliciesForV1_13 (); err != nil {
94
+ return err
95
+ }
96
+ return nil
97
+ }
98
+
65
99
func (c * Controller ) createAsForNetpol (ns , name , direction , asName string , addresses []string ) error {
66
100
if err := c .OVNNbClient .CreateAddressSet (asName , map [string ]string {
67
101
networkPolicyKey : fmt .Sprintf ("%s/%s/%s" , ns , name , direction ),
@@ -165,7 +199,7 @@ func (c *Controller) handleUpdateNp(key string) error {
165
199
return err
166
200
}
167
201
168
- ingressACLOps , err := c .OVNNbClient .DeleteAclsOps (pgName , portGroupKey , "to-lport" , nil )
202
+ ingressACLOps , err := c .OVNNbClient .DeleteAclsOps (pgName , portGroupKey , "to-lport" , nil , - 1 )
169
203
if err != nil {
170
204
klog .Errorf ("generate operations that clear np %s ingress acls: %v" , key , err )
171
205
return err
@@ -281,7 +315,7 @@ func (c *Controller) handleUpdateNp(key string) error {
281
315
}
282
316
}
283
317
} else {
284
- if err = c .OVNNbClient .DeleteAcls (pgName , portGroupKey , "to-lport" , nil ); err != nil {
318
+ if err = c .OVNNbClient .DeleteAcls (pgName , portGroupKey , "to-lport" , nil , - 1 ); err != nil {
285
319
klog .Errorf ("delete np %s ingress acls: %v" , key , err )
286
320
return err
287
321
}
@@ -294,7 +328,7 @@ func (c *Controller) handleUpdateNp(key string) error {
294
328
}
295
329
}
296
330
297
- egressACLOps , err := c .OVNNbClient .DeleteAclsOps (pgName , portGroupKey , "from-lport" , nil )
331
+ egressACLOps , err := c .OVNNbClient .DeleteAclsOps (pgName , portGroupKey , "from-lport" , nil , - 1 )
298
332
if err != nil {
299
333
klog .Errorf ("generate operations that clear np %s egress acls: %v" , key , err )
300
334
return err
@@ -408,7 +442,7 @@ func (c *Controller) handleUpdateNp(key string) error {
408
442
}
409
443
}
410
444
} else {
411
- if err = c .OVNNbClient .DeleteAcls (pgName , portGroupKey , "from-lport" , nil ); err != nil {
445
+ if err = c .OVNNbClient .DeleteAcls (pgName , portGroupKey , "from-lport" , nil , - 1 ); err != nil {
412
446
klog .Errorf ("delete np %s egress acls: %v" , key , err )
413
447
return err
414
448
}
0 commit comments