Skip to content

Commit

Permalink
Fix: one NIC's IP pool shortage depleted IPs of other NICs in a multi…
Browse files Browse the repository at this point in the history
…-NIC setup.

Signed-off-by: tao.yang <[email protected]>
  • Loading branch information
weizhoublue authored and ty-dc committed Dec 11, 2024
1 parent 9ae8fb3 commit d9035f9
Show file tree
Hide file tree
Showing 3 changed files with 552 additions and 193 deletions.
10 changes: 9 additions & 1 deletion pkg/ippoolmanager/ippool_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ func (im *ipPoolManager) genRandomIP(ctx context.Context, ipPool *spiderpoolv2be
}

var used []string
for ip := range allocatedRecords {
for ip, record := range allocatedRecords {
// In a multi-NIC scenario, if one of the NIC pools does not have enough IPs, an allocation failure message will be displayed.
// However, other IP pools still have IPs, which will cause IPs in other pools to be exhausted.
// Check if there is a duplicate Pod UID in IPPool.allocatedRecords.
// If so, we skip this allocation and assume that this Pod has already obtained an IP address in the pool.
if record.PodUID == string(pod.UID) {
logger.Sugar().Warnf("The Pod %s/%s UID %s already exists in the assigned IP %s", pod.Namespace, pod.Name, ip, string(pod.UID))
return net.ParseIP(ip), nil
}
used = append(used, ip)
}
usedIPs, err := spiderpoolip.ParseIPRanges(*ipPool.Spec.IPVersion, used)
Expand Down
6 changes: 5 additions & 1 deletion test/doc/annotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
| A00009 | Modify the annotated IPPool for a specified Deployment pod<br />Modify the annotated IPPool for a specified StatefulSet pod | p2 | | done | |
| A00010 | Modify the annotated IPPool for a pod running on multiple NICs | p3 | | done | |
| A00011 | Use the ippool route with `cleanGateway=false` in the pod annotation as a default route | p3 | | done | |
| A00012 | Specify the default NIC through Pod annotations | p2 | | | |
| A00012 | Specify the default route NIC through Pod annotation: `ipam.spidernet.io/default-route-nic` | p2 | | done | |
| A00013 | It's invalid to specify one NIC corresponding IPPool in IPPools annotation with multiple NICs | p2 | | done | |
| A00014 | It's invalid to specify same NIC name for IPPools annotation with multiple NICs | p2 | | done | |
| A00015 | Use wildcard for 'ipam.spidernet.io/ippools' annotation to specify IPPools | p2 | | done | |
| A00016 | In the annotation ipam.spidernet.io/ippools for multi-NICs, when the IP pool for one NIC runs out of IPs, it should not exhaust IPs from other pools. | p2 | | done | |
Loading

0 comments on commit d9035f9

Please sign in to comment.