@@ -1381,59 +1381,61 @@ func needRouteSubnets(pod *v1.Pod, nets []*kubeovnNet) []*kubeovnNet {
1381
1381
}
1382
1382
1383
1383
func (c * Controller ) getPodDefaultSubnet (pod * v1.Pod ) (* kubeovnv1.Subnet , error ) {
1384
- var subnet * kubeovnv1.Subnet
1385
- var err error
1386
- // 1. check annotation subnet
1387
- lsName , lsExist := pod .Annotations [util .LogicalSwitchAnnotation ]
1388
- if lsExist {
1389
- subnet , err = c .subnetsLister .Get (lsName )
1384
+ // check pod annotations
1385
+ if lsName := pod .Annotations [util .LogicalSwitchAnnotation ]; lsName != "" {
1386
+ subnet , err := c .subnetsLister .Get (lsName )
1390
1387
if err != nil {
1391
- klog .Errorf ("failed to get subnet %v" , err )
1388
+ klog .Errorf ("failed to get subnet %s: %v" , lsName , err )
1392
1389
return nil , err
1393
1390
}
1394
- } else {
1395
- ns , err := c .namespacesLister .Get (pod .Namespace )
1396
- if err != nil {
1397
- klog .Errorf ("failed to get namespace %s, %v" , pod .Namespace , err )
1391
+ return subnet , nil
1392
+ }
1393
+
1394
+ ns , err := c .namespacesLister .Get (pod .Namespace )
1395
+ if err != nil {
1396
+ klog .Errorf ("failed to get namespace %s: %v" , pod .Namespace , err )
1397
+ return nil , err
1398
+ }
1399
+ if len (ns .Annotations ) == 0 {
1400
+ err = fmt .Errorf ("namespace %s network annotations is empty" , ns .Name )
1401
+ klog .Error (err )
1402
+ return nil , err
1403
+ }
1404
+
1405
+ subnetNames := ns .Annotations [util .LogicalSwitchAnnotation ]
1406
+ for _ , subnetName := range strings .Split (subnetNames , "," ) {
1407
+ if subnetName == "" {
1408
+ err = fmt .Errorf ("namespace %s default logical switch is not found" , ns .Name )
1409
+ klog .Error (err )
1398
1410
return nil , err
1399
1411
}
1400
- if ns . Annotations == nil {
1401
- err = fmt . Errorf ( "namespace %s network annotations is nil" , pod . Namespace )
1402
- klog .Error ( err )
1412
+ subnet , err := c . subnetsLister . Get ( subnetName )
1413
+ if err != nil {
1414
+ klog .Errorf ( "failed to get subnet %s: %v" , subnetName , err )
1403
1415
return nil , err
1404
1416
}
1405
1417
1406
- subnetNames := ns .Annotations [util .LogicalSwitchAnnotation ]
1407
- for _ , subnetName := range strings .Split (subnetNames , "," ) {
1408
- if subnetName == "" {
1409
- err = fmt .Errorf ("namespace %s default logical switch is not found" , pod .Namespace )
1410
- klog .Error (err )
1411
- return nil , err
1418
+ switch subnet .Spec .Protocol {
1419
+ case kubeovnv1 .ProtocolDual :
1420
+ if subnet .Status .V6AvailableIPs == 0 {
1421
+ klog .Infof ("there's no available ipv6 address in subnet %s, try next one" , subnet .Name )
1422
+ continue
1412
1423
}
1413
- subnet , err = c .subnetsLister .Get (subnetName )
1414
- if err != nil {
1415
- klog .Errorf ("failed to get subnet %v" , err )
1416
- return nil , err
1424
+ fallthrough
1425
+ case kubeovnv1 .ProtocolIPv4 :
1426
+ if subnet .Status .V4AvailableIPs == 0 {
1427
+ klog .Infof ("there's no available ipv4 address in subnet %s, try next one" , subnet .Name )
1428
+ continue
1417
1429
}
1418
-
1419
- switch subnet .Spec .Protocol {
1420
- case kubeovnv1 .ProtocolIPv4 :
1421
- fallthrough
1422
- case kubeovnv1 .ProtocolDual :
1423
- if subnet .Status .V4AvailableIPs == 0 {
1424
- klog .V (3 ).Infof ("there's no available ips for subnet %v, try next subnet" , subnet .Name )
1425
- continue
1426
- }
1427
- case kubeovnv1 .ProtocolIPv6 :
1428
- if subnet .Status .V6AvailableIPs == 0 {
1429
- klog .Infof ("there's no available ips for subnet %v, try next subnet" , subnet .Name )
1430
- continue
1431
- }
1430
+ case kubeovnv1 .ProtocolIPv6 :
1431
+ if subnet .Status .V6AvailableIPs == 0 {
1432
+ klog .Infof ("there's no available ipv6 address in subnet %s, try next one" , subnet .Name )
1433
+ continue
1432
1434
}
1433
- break
1434
1435
}
1436
+ return subnet , nil
1435
1437
}
1436
- return subnet , nil
1438
+ return nil , ipam . ErrNoAvailable
1437
1439
}
1438
1440
1439
1441
func loadNetConf (bytes []byte ) (* multustypes.DelegateNetConf , error ) {
0 commit comments