@@ -1438,49 +1438,54 @@ func (c *Controller) acquireAddress(pod *v1.Pod, podNet *kubeovnNet) (string, st
1438
1438
}
1439
1439
1440
1440
// IPPool allocate
1441
- ipPool := strings .Split (pod .Annotations [fmt .Sprintf (util .IpPoolAnnotationTemplate , podNet .ProviderName )], ";" )
1442
- for i , ip := range ipPool {
1443
- ipPool [i ] = strings .TrimSpace (ip )
1444
- }
1441
+ if pod .Annotations [fmt .Sprintf (util .IpPoolAnnotationTemplate , podNet .ProviderName )] != "" {
1442
+ var ipPool []string
1443
+ if strings .Contains (pod .Annotations [fmt .Sprintf (util .IpPoolAnnotationTemplate , podNet .ProviderName )], ";" ) {
1444
+ ipPool = strings .Split (pod .Annotations [fmt .Sprintf (util .IpPoolAnnotationTemplate , podNet .ProviderName )], ";" )
1445
+ } else {
1446
+ ipPool = strings .Split (pod .Annotations [fmt .Sprintf (util .IpPoolAnnotationTemplate , podNet .ProviderName )], "," )
1447
+ }
1448
+ for i , ip := range ipPool {
1449
+ ipPool [i ] = strings .TrimSpace (ip )
1450
+ }
1445
1451
1446
- if ! isStsPod {
1447
- for _ , net := range nsNets {
1448
- for _ , staticIPs := range ipPool {
1449
- ipProtocol := util .CheckProtocol (staticIPs )
1450
- for _ , staticIP := range strings .Split (staticIPs , "," ) {
1451
- if assignedPod , ok := c .ipam .IsIPAssignedToOtherPod (staticIP , net .Subnet .Name , key ); ok {
1452
+ if ! isStsPod {
1453
+ for _ , net := range nsNets {
1454
+ for _ , staticIP := range ipPool {
1455
+ var checkIP string
1456
+ ipProtocol := util .CheckProtocol (staticIP )
1457
+ if ipProtocol == kubeovnv1 .ProtocolDual {
1458
+ checkIP = strings .Split (staticIP , "," )[0 ]
1459
+ } else {
1460
+ checkIP = staticIP
1461
+ }
1462
+
1463
+ if assignedPod , ok := c .ipam .IsIPAssignedToOtherPod (checkIP , net .Subnet .Name , key ); ok {
1452
1464
klog .Errorf ("static address %s for %s has been assigned to %s" , staticIP , key , assignedPod )
1453
1465
continue
1454
1466
}
1455
1467
1456
- if ipProtocol != kubeovnv1 .ProtocolDual {
1457
- v4IP , v6IP , mac , err = c .acquireStaticAddress (key , portName , staticIP , macStr , net .Subnet .Name , net .AllowLiveMigration )
1458
- if err == nil {
1459
- return v4IP , v6IP , mac , net .Subnet , nil
1460
- }
1461
- }
1462
- }
1463
- if ipProtocol == kubeovnv1 .ProtocolDual {
1464
- v4IP , v6IP , mac , err = c .acquireStaticAddress (key , portName , staticIPs , macStr , net .Subnet .Name , net .AllowLiveMigration )
1468
+ v4IP , v6IP , mac , err = c .acquireStaticAddress (key , portName , staticIP , macStr , net .Subnet .Name , net .AllowLiveMigration )
1465
1469
if err == nil {
1466
1470
return v4IP , v6IP , mac , net .Subnet , nil
1467
1471
}
1468
1472
}
1469
1473
}
1470
- }
1471
- klog .Errorf ("acquire address %s for %s failed, %v" , pod .Annotations [fmt .Sprintf (util .IpPoolAnnotationTemplate , podNet .ProviderName )], key , err )
1472
- } else {
1473
- tempStrs := strings .Split (pod .Name , "-" )
1474
- numStr := tempStrs [len (tempStrs )- 1 ]
1475
- index , _ := strconv .Atoi (numStr )
1476
- if index < len (ipPool ) {
1477
- for _ , net := range nsNets {
1478
- v4IP , v6IP , mac , err = c .acquireStaticAddress (key , portName , ipPool [index ], macStr , net .Subnet .Name , net .AllowLiveMigration )
1479
- if err == nil {
1480
- return v4IP , v6IP , mac , net .Subnet , nil
1474
+ klog .Errorf ("acquire address %s for %s failed, %v" , pod .Annotations [fmt .Sprintf (util .IpPoolAnnotationTemplate , podNet .ProviderName )], key , err )
1475
+ } else {
1476
+ tempStrs := strings .Split (pod .Name , "-" )
1477
+ numStr := tempStrs [len (tempStrs )- 1 ]
1478
+ index , _ := strconv .Atoi (numStr )
1479
+
1480
+ if index < len (ipPool ) {
1481
+ for _ , net := range nsNets {
1482
+ v4IP , v6IP , mac , err = c .acquireStaticAddress (key , portName , ipPool [index ], macStr , net .Subnet .Name , net .AllowLiveMigration )
1483
+ if err == nil {
1484
+ return v4IP , v6IP , mac , net .Subnet , nil
1485
+ }
1481
1486
}
1487
+ klog .Errorf ("acquire address %s for %s failed, %v" , ipPool [index ], key , err )
1482
1488
}
1483
- klog .Errorf ("acquire address %s for %s failed, %v" , ipPool [index ], key , err )
1484
1489
}
1485
1490
}
1486
1491
klog .Errorf ("alloc address for %s failed, return NoAvailableAddress" , key )
0 commit comments