Skip to content

Treat semantically-equal IP pool CIDRs as equal - #4918

Merged
tmjd merged 1 commit into
tigera:masterfrom
tmjd:fix-noncanonical-ipv6-ippool-cidr-4783
Jun 15, 2026
Merged

tmjd merged 1 commit into
tigera:masterfrom
tmjd:fix-noncanonical-ipv6-ippool-cidr-4783

Conversation

@tmjd

@tmjd tmjd commented Jun 12, 2026

Copy link
Copy Markdown
Member

Description

Bug fix for the IP pool controller (pkg/controller/ippool).

When an Installation specifies an IPv6 pool CIDR in a non-canonical form (e.g. with leading zeros, fd20:5213:94f6:01e9:001f::/96), the controller entered an infinite delete/recreate loop:

  1. The existing pool is stored with the canonical CIDR (fd20:5213:94f6:1e9:1f::/96), because the Calico API server normalizes CIDRs via net.ParseCIDR when persisting pools.
  2. The controller compared CIDRs as raw strings (p.CIDR == cidr), so it concluded the existing pool was not the one described in the Installation.
  3. It marked the pool for deletion and recreated it from the Installation CIDR β€” which the API server re-normalized β€” returning to step 1, forever.

Why merge: this leaves affected clusters with an operator that churns IP pools indefinitely after upgrade; the only workaround today is to hand-edit the CIDR into canonical form.

Fix: compare CIDRs by their canonical form (net.IPNet.String()) everywhere the controller keys or matches pools by CIDR β€” the ourPools ownership map, adoption of pre-existing unlabelled pools, the notOurs not-owned detection, the create/update decision, and the delete check. The controller also now emits the canonical CIDR when creating/updating pools (ToProjectCalico) so the written resource matches what the API server stores (avoiding needless updates) and is accepted by API server versions that reject non-canonical CIDRs (see projectcalico/calico#11385). Unparseable CIDRs fall back to exact string comparison.

Components affected: IP pool controller only.

Testing:

  • Added a regression unit test that reproduces the loop. With the fix reverted, the test fails β€” the pool is deleted and recreated with the non-canonical CIDR. With the fix, the pool is left untouched (canonical CIDR, single pool) across repeated reconciles.
  • make ut UT_DIR=./pkg/controller/ippool passes; gofmt clean.

Fixes #4783

Release Note

Fixed an infinite IP pool delete/recreate loop that occurred when an Installation specified an IP pool CIDR in non-canonical form (for example an IPv6 CIDR with leading zeros).

For PR author

  • Tests for change.
  • If changing pkg/apis/, run make gen-files
  • If changing versions, run make gen-versions

For PR reviewers

A note for code reviewers - all pull requests must have the following:

  • Milestone set according to targeted release.
  • Appropriate labels:
    • kind/bug if this is a bugfix.
    • kind/enhancement if this is a a new feature.
    • enterprise if this PR applies to Calico Enterprise only.

After upgrading, an Installation that specifies an IPv6 pool CIDR in a
non-canonical form (e.g. with leading zeros, "fd20:5213:94f6:01e9:001f::/96")
caused the IP pool controller to enter an infinite delete/recreate loop. The
Calico API server normalizes CIDRs when it stores IP pools, so the persisted
pool has the canonical CIDR ("fd20:5213:94f6:1e9:1f::/96"). The controller
compared CIDRs as raw strings, decided the existing pool was not the one
described in the Installation, deleted it, and recreated it -- which the API
server then re-normalized, repeating forever.

Compare CIDRs by their canonical form everywhere the controller keys or
matches pools by CIDR (ownership lookup, adoption of pre-existing pools,
not-owned detection, create/update decision, and the delete check), and emit
the canonical CIDR when creating/updating pools so the stored resource matches
what we expect and is accepted by API server versions that reject
non-canonical CIDRs.

Fixes tigera#4783

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@radTuti radTuti modified the milestones: v1.43.0, v1.44.0 Jun 12, 2026
@tmjd
tmjd merged commit f444e3b into tigera:master Jun 15, 2026
9 checks passed
@tmjd
tmjd deleted the fix-noncanonical-ipv6-ippool-cidr-4783 branch July 9, 2026 12:50
@danudey danudey added the kind/bug Something isn't working label Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite loop when using non-canonical IPv6 in IPPool CIDR

5 participants