@@ -1634,18 +1634,18 @@ func (c *Controller) getPodDefaultSubnet(pod *v1.Pod) (*kubeovnv1.Subnet, error)
1634
1634
1635
1635
switch subnet .Spec .Protocol {
1636
1636
case kubeovnv1 .ProtocolDual :
1637
- if subnet .Status .V6AvailableIPs == 0 {
1637
+ if subnet .Status .V6AvailableIPs == 0 && ! c . podCanUseExcludeIPs ( pod , subnet ) {
1638
1638
klog .Infof ("there's no available ipv6 address in subnet %s, try next one" , subnet .Name )
1639
1639
continue
1640
1640
}
1641
1641
fallthrough
1642
1642
case kubeovnv1 .ProtocolIPv4 :
1643
- if subnet .Status .V4AvailableIPs == 0 {
1643
+ if subnet .Status .V4AvailableIPs == 0 && ! c . podCanUseExcludeIPs ( pod , subnet ) {
1644
1644
klog .Infof ("there's no available ipv4 address in subnet %s, try next one" , subnet .Name )
1645
1645
continue
1646
1646
}
1647
1647
case kubeovnv1 .ProtocolIPv6 :
1648
- if subnet .Status .V6AvailableIPs == 0 {
1648
+ if subnet .Status .V6AvailableIPs == 0 && ! c . podCanUseExcludeIPs ( pod , subnet ) {
1649
1649
klog .Infof ("there's no available ipv6 address in subnet %s, try next one" , subnet .Name )
1650
1650
continue
1651
1651
}
@@ -1669,6 +1669,36 @@ func loadNetConf(bytes []byte) (*multustypes.DelegateNetConf, error) {
1669
1669
return delegateConf , nil
1670
1670
}
1671
1671
1672
+ func (c * Controller ) podCanUseExcludeIPs (pod * v1.Pod , subnet * kubeovnv1.Subnet ) bool {
1673
+ if ipAddr := pod .Annotations [util .IPAddressAnnotation ]; ipAddr != "" {
1674
+ return c .checkIPsInExcludeList (ipAddr , subnet .Spec .ExcludeIps , subnet .Spec .CIDRBlock )
1675
+ }
1676
+ if ipPool := pod .Annotations [util .IPPoolAnnotation ]; ipPool != "" {
1677
+ return c .checkIPsInExcludeList (ipPool , subnet .Spec .ExcludeIps , subnet .Spec .CIDRBlock )
1678
+ }
1679
+
1680
+ return false
1681
+ }
1682
+
1683
+ func (c * Controller ) checkIPsInExcludeList (ips string , excludeIPs []string , cidr string ) bool {
1684
+ expandedExcludeIPs := util .ExpandExcludeIPs (excludeIPs , cidr )
1685
+
1686
+ for ipAddr := range strings .SplitSeq (strings .TrimSpace (ips ), "," ) {
1687
+ ipAddr = strings .TrimSpace (ipAddr )
1688
+ if ipAddr == "" {
1689
+ continue
1690
+ }
1691
+
1692
+ for _ , excludeIP := range expandedExcludeIPs {
1693
+ if util .ContainsIPs (excludeIP , ipAddr ) {
1694
+ klog .V (3 ).Infof ("IP %s is found in exclude IP %s, allowing allocation" , ipAddr , excludeIP )
1695
+ return true
1696
+ }
1697
+ }
1698
+ }
1699
+ return false
1700
+ }
1701
+
1672
1702
type providerType int
1673
1703
1674
1704
const (
0 commit comments