← Back to Pull requests

fix(ipam): reject a wildcard IPPool selection that matches no IPPool #5862

Closed
unknown closed this pull request without merging on Nov 05, 2026 06:32 UTC
View on GitHub
unknown unknown commented on Oct 29, 2026 11:04 UTC
Author

Thanks for contributing!

Notice:

[x] unite test or E2E test
[x] do not forget essential code comment and log
[ ] document for the PR
[x] release note label: release/bug
[x] read about Contribution notice: <https://spidernet-io.github.io/spiderpool/latest/develop/contributing/>

What issue(s) does this PR fix:

Fixes #5849

Special notes for your reviewer:

ParseWildcardPoolNameList expands wildcard IPPool names against the IPPools that already exist for the requested IP version, and a selection can also resolve to nothing when every pool listed belongs to an IP family that is disabled on the cluster. Either way pkg/ipam used to continue with an empty candidate list, the agent answered the CNI ADD with {"ips":null}, and the Pod failed with ips in body is required, which points nowhere near the pool name.

Following the review in this thread, the check sits in genToBeAllocatedSet right after checkIPVersionEnable, so it covers every selection path once the candidates are filtered by family:

for _, t := range preliminary {
    if len(t.PoolCandidates) == 0 {
        return nil, fmt.Errorf("%w, no IPPool candidate left for NIC %s", constant.ErrNoAvailablePool, t.NIC)
    }
}

ParseWildcardPoolNameList keeps its signature and only logs a Warn when a pattern matches nothing, because it cannot know which IP families the caller has enabled.

Scope notes:

The error wraps constant.ErrNoAvailablePool, the sentinel the agent already counts at cmd/spiderpool-agent/cmd/ipam.go:172, so the failure now also shows up in the no-available-pool metric.
The eight calls in pkg/ipam/pool_selections.go are untouched. They cover four selection paths, each with an IPv4 and an IPv6 call: the Pod annotation ipam.spidernet.io/ippools, the legacy ippool annotation, the namespace default pools, and the NAD fields default_ipv4_ippool / default_ipv6_ippool. They reach the new check through genToBeAllocatedSet.
A mixed list such as ["vlan-a", "zero-"], where vlan-a exists, still allocates, because one candidate is left. Per-pattern strictness is the separate question in #5861.
A pool list of a disabled IP family now fails the same way an empty wildcard does, which is what the review asked for. One corner is still open in the thread: a multi-NIC ippools entry that lists no pool at all.

  • The case in pkg/ippoolmanager keeps expecting no error for a zero-match wildcard, and two cases in pkg/ipam cover the disabled family and the empty wildcard.
  • Manual reproduction of the original symptom is in #5849: the agent logged Prechecked IPPool candidates: [{NIC:eth0 CleanGateway:false PoolCandidates:[]}], then Succeed to allocate: {"ips":null}, and the Pod event was ips in body is required. The new check sits where that empty list shows up. After the review change I did not rerun the Pods, because my local kind lab is gone and rebuilding it needs the multus and controller images pulled again. I can do that before merge if you would like the real event.

    go test ./pkg/ippoolmanager ./pkg/ipam passes, gofmt -l, go vet ./pkg/ippoolmanager and make check_test_label are clean. No user-facing documentation change. I did not add an E2E case, since the behaviour here is covered by the unit tests. Say if you want one in the IPAM suite and I will add it.

    AI disclosure: I used AI assistance to help write this change and its tests. The reproduction above and the code are mine.

    Release note:

    ``release-note
    A pool selection that leaves no IPPool candidate for a NIC, for example a wildcard that matches no IPPool or a pool list whose IP family is disabled, now fails with an explicit "no IPPool candidate left for NIC" error instead of leaving the Pod to fail with the unrelated "ips in body is required" message.
    ``

    Diff: 479 lines (+359 / -120) across 5 files Reviewer: bolubo Review duration: 9807m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 479 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.369
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5862"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.8% (MEDIUM) · Higher = larger blast radius
    45.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.1% · Safe to merge
    18.1%