From 82009ed898d2e73addd4187315edeb59f0edca83 Mon Sep 17 00:00:00 2001 From: Serge Logvinov Date: Mon, 21 Oct 2024 18:47:21 +0300 Subject: [PATCH] feat: ipv6 small subnets Set a limit of 32 pods per node in your Kubernetes cluster. Some cloud providers offer a /123 IPv6 subnet for nodes, which is typically sufficient for most use cases. Signed-off-by: Serge Logvinov --- pkg/nodeipam/ipam/cloud_allocator.go | 4 +++- pkg/nodeipam/ipam/cloud_allocator_test.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/nodeipam/ipam/cloud_allocator.go b/pkg/nodeipam/ipam/cloud_allocator.go index 94b374c..56c2b78 100644 --- a/pkg/nodeipam/ipam/cloud_allocator.go +++ b/pkg/nodeipam/ipam/cloud_allocator.go @@ -628,8 +628,10 @@ func (r *cloudAllocator) addCIDRSet(cidr string) error { } mask = 80 - case mask > 120: + case mask > 123: return fmt.Errorf("CIDRv6 is too small: %v", subnet.String()) + case mask > 119: + break default: mask += 16 } diff --git a/pkg/nodeipam/ipam/cloud_allocator_test.go b/pkg/nodeipam/ipam/cloud_allocator_test.go index 49ec073..ba24660 100644 --- a/pkg/nodeipam/ipam/cloud_allocator_test.go +++ b/pkg/nodeipam/ipam/cloud_allocator_test.go @@ -65,11 +65,23 @@ func TestAddCIDRSet(t *testing.T) { expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:bbbb:cccc:0/112"), }, { - name: "CIDRv6 with mask size 120", + name: "CIDRv6 with mask size 120, 256 pods", cidr: "2000::aaaa:bbbb:cccc:123/120", expectedSize: 1, expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:bbbb:cccc:100/120"), }, + { + name: "CIDRv6 with mask size 122, 64 pods", + cidr: "2000::aaaa:bbbb:cccc:123/122", + expectedSize: 1, + expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:bbbb:cccc:100/122"), + }, + { + name: "CIDRv6 with mask size 123, 32 pods", + cidr: "2000::aaaa:bbbb:cccc:123/123", + expectedSize: 1, + expectedClusterCIDR: netip.MustParsePrefix("2000::aaaa:bbbb:cccc:120/123"), + }, { name: "CIDRv6 with mask size 124", cidr: "2000::aaaa:bbbb:cccc:123/124",