@@ -92,7 +92,9 @@ func (c *Controller) enqueueUpdateSubnet(old, new interface{}) {
92
92
oldSubnet .Spec .Gateway != newSubnet .Spec .Gateway ||
93
93
! reflect .DeepEqual (oldSubnet .Spec .ExcludeIps , newSubnet .Spec .ExcludeIps ) ||
94
94
oldSubnet .Spec .Vlan != newSubnet .Spec .Vlan ||
95
- oldSubnet .Spec .U2OInterconnection != newSubnet .Spec .U2OInterconnection {
95
+ oldSubnet .Spec .U2OInterconnection != newSubnet .Spec .U2OInterconnection ||
96
+ (newSubnet .Spec .U2OInterconnection && newSubnet .Spec .U2OInterconnectionIP != "" &&
97
+ oldSubnet .Spec .U2OInterconnectionIP != newSubnet .Spec .U2OInterconnectionIP ) {
96
98
klog .V (3 ).Infof ("enqueue update subnet %s" , key )
97
99
c .addOrUpdateSubnetQueue .Add (key )
98
100
}
@@ -274,6 +276,11 @@ func formatSubnet(subnet *kubeovnv1.Subnet, c *Controller) error {
274
276
}
275
277
}
276
278
}
279
+ if subnet .Spec .U2OInterconnectionIP != "" && ! subnet .Spec .U2OInterconnection {
280
+ subnet .Spec .U2OInterconnectionIP = ""
281
+ changed = true
282
+ }
283
+
277
284
klog .Infof ("format subnet %v, changed %v" , subnet .Name , changed )
278
285
if changed {
279
286
_ , err = c .config .KubeOvnClient .KubeovnV1 ().Subnets ().Update (context .Background (), subnet , metav1.UpdateOptions {})
@@ -1219,14 +1226,29 @@ func (c *Controller) reconcileU2OInterconnectionIP(subnet *kubeovnv1.Subnet) err
1219
1226
klog .Infof ("reconcile underlay subnet %s to overlay interconnection with U2OInterconnection %v U2OInterconnectionIP %s " ,
1220
1227
subnet .Name , subnet .Spec .U2OInterconnection , subnet .Status .U2OInterconnectionIP )
1221
1228
if subnet .Spec .U2OInterconnection {
1222
- if subnet .Status .U2OInterconnectionIP == "" {
1223
- u2oInterconnName := fmt .Sprintf (util .U2OInterconnName , subnet .Spec .Vpc , subnet .Name )
1224
- u2oInterconnLrpName := fmt .Sprintf ("%s-%s" , subnet .Spec .Vpc , subnet .Name )
1225
- v4ip , v6ip , _ , err := c .acquireIpAddress (subnet .Name , u2oInterconnName , u2oInterconnLrpName )
1229
+ u2oInterconnName := fmt .Sprintf (util .U2OInterconnName , subnet .Spec .Vpc , subnet .Name )
1230
+ u2oInterconnLrpName := fmt .Sprintf ("%s-%s" , subnet .Spec .Vpc , subnet .Name )
1231
+ var v4ip , v6ip string
1232
+ var err error
1233
+ if subnet .Spec .U2OInterconnectionIP == "" && subnet .Status .U2OInterconnectionIP == "" {
1234
+ v4ip , v6ip , _ , err = c .acquireIpAddress (subnet .Name , u2oInterconnName , u2oInterconnLrpName )
1226
1235
if err != nil {
1227
1236
klog .Errorf ("failed to acquire underlay to overlay interconnection ip address for subnet %s, %v" , subnet .Name , err )
1228
1237
return err
1229
1238
}
1239
+ } else if subnet .Spec .U2OInterconnectionIP != "" && subnet .Status .U2OInterconnectionIP != subnet .Spec .U2OInterconnectionIP {
1240
+ if subnet .Status .U2OInterconnectionIP != "" {
1241
+ c .ipam .ReleaseAddressByPod (u2oInterconnName )
1242
+ }
1243
+
1244
+ v4ip , v6ip , _ , err = c .acquireStaticIpAddress (subnet .Name , u2oInterconnName , u2oInterconnLrpName , subnet .Spec .U2OInterconnectionIP )
1245
+ if err != nil {
1246
+ klog .Errorf ("failed to acquire static underlay to overlay interconnection ip address for subnet %s, %v" , subnet .Name , err )
1247
+ return err
1248
+ }
1249
+ }
1250
+
1251
+ if v4ip != "" || v6ip != "" {
1230
1252
switch subnet .Spec .Protocol {
1231
1253
case kubeovnv1 .ProtocolIPv4 :
1232
1254
subnet .Status .U2OInterconnectionIP = v4ip
@@ -1943,3 +1965,20 @@ func (c *Controller) acquireIpAddress(subnetName, name, nicName string) (string,
1943
1965
}
1944
1966
}
1945
1967
}
1968
+
1969
+ func (c * Controller ) acquireStaticIpAddress (subnetName , name , nicName , ip string ) (string , string , string , error ) {
1970
+ checkConflict := true
1971
+ var v4ip , v6ip , mac string
1972
+ var err error
1973
+ for _ , ipStr := range strings .Split (ip , "," ) {
1974
+ if net .ParseIP (ipStr ) == nil {
1975
+ return "" , "" , "" , fmt .Errorf ("failed to parse vip ip %s" , ipStr )
1976
+ }
1977
+ }
1978
+
1979
+ if v4ip , v6ip , mac , err = c .ipam .GetStaticAddress (name , nicName , ip , "" , subnetName , checkConflict ); err != nil {
1980
+ klog .Errorf ("failed to get static virtual ip '%s', mac '%s', subnet '%s', %v" , ip , mac , subnetName , err )
1981
+ return "" , "" , "" , err
1982
+ }
1983
+ return v4ip , v6ip , mac , nil
1984
+ }
0 commit comments