Skip to content

Commit 42bbf13

Browse files
authored
Fix the problem that if available ip is 0 but there is a value in excludeIPs, the fixed ip is used as the ip in excludeIPs but the error noAddressAvaliable is still reported. (#5565)
Signed-off-by: clyi <[email protected]>
1 parent b0f333c commit 42bbf13

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

pkg/controller/pod.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,18 +1634,18 @@ func (c *Controller) getPodDefaultSubnet(pod *v1.Pod) (*kubeovnv1.Subnet, error)
16341634

16351635
switch subnet.Spec.Protocol {
16361636
case kubeovnv1.ProtocolDual:
1637-
if subnet.Status.V6AvailableIPs == 0 {
1637+
if subnet.Status.V6AvailableIPs == 0 && !c.podCanUseExcludeIPs(pod, subnet) {
16381638
klog.Infof("there's no available ipv6 address in subnet %s, try next one", subnet.Name)
16391639
continue
16401640
}
16411641
fallthrough
16421642
case kubeovnv1.ProtocolIPv4:
1643-
if subnet.Status.V4AvailableIPs == 0 {
1643+
if subnet.Status.V4AvailableIPs == 0 && !c.podCanUseExcludeIPs(pod, subnet) {
16441644
klog.Infof("there's no available ipv4 address in subnet %s, try next one", subnet.Name)
16451645
continue
16461646
}
16471647
case kubeovnv1.ProtocolIPv6:
1648-
if subnet.Status.V6AvailableIPs == 0 {
1648+
if subnet.Status.V6AvailableIPs == 0 && !c.podCanUseExcludeIPs(pod, subnet) {
16491649
klog.Infof("there's no available ipv6 address in subnet %s, try next one", subnet.Name)
16501650
continue
16511651
}
@@ -1669,6 +1669,36 @@ func loadNetConf(bytes []byte) (*multustypes.DelegateNetConf, error) {
16691669
return delegateConf, nil
16701670
}
16711671

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+
16721702
type providerType int
16731703

16741704
const (

0 commit comments

Comments
 (0)