Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPAM multipool followups #26138

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion operator/cmd/cilium_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s *ciliumNodeSynchronizer) Start(ctx context.Context, wg *sync.WaitGroup)
},
func(node *cilium_v2.CiliumNode) {
// node is deep copied before it is stored in pkg/aws/eni
s.nodeManager.Update(node)
s.nodeManager.Upsert(node)
})
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/alibabacloud/eni/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (e *ENISuite) TestCreateInterface(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(mngr, check.Not(check.IsNil))

mngr.Update(newCiliumNode("node1", "i-1", "ecs.g7ne.large", "cn-hangzhou-i", "vpc-1"))
mngr.Update(newCiliumNode("node2", "i-2", "ecs.g7ne.large", "cn-hangzhou-h", "vpc-1"))
mngr.Upsert(newCiliumNode("node1", "i-1", "ecs.g7ne.large", "cn-hangzhou-i", "vpc-1"))
mngr.Upsert(newCiliumNode("node2", "i-2", "ecs.g7ne.large", "cn-hangzhou-h", "vpc-1"))
names := mngr.GetNames()
c.Assert(len(names), check.Equals, 2)

Expand Down Expand Up @@ -113,7 +113,7 @@ func (e *ENISuite) TestCandidateAndEmtpyInterfaces(c *check.C) {
// Set PreAllocate as 1
cn := newCiliumNodeWithIpamParams("node3", "i-3", "ecs.g8m.small", "cn-hangzhou-h", "vpc-1", 1, 0, 0)
cn.Spec.AlibabaCloud.VSwitches = []string{"vsw-2"}
mngr.Update(cn)
mngr.Upsert(cn)

n := &Node{}
n.k8sObj = cn
Expand All @@ -140,7 +140,7 @@ func (e *ENISuite) TestPrepareIPAllocation(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(mngr, check.Not(check.IsNil))

mngr.Update(newCiliumNode("node1", "i-1", "ecs.g7ne.large", "cn-hangzhou-i", "vpc-1"))
mngr.Upsert(newCiliumNode("node1", "i-1", "ecs.g7ne.large", "cn-hangzhou-i", "vpc-1"))
a, err := mngr.Get("node1").Ops().PrepareIPAllocation(log)
c.Assert(err, check.IsNil)
c.Assert(a.EmptyInterfaceSlots+a.InterfaceCandidates, check.Equals, 2)
Expand Down
62 changes: 31 additions & 31 deletions pkg/aws/eni/node_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func (e *ENISuite) TestGetNodeNames(c *check.C) {
c.Assert(mngr, check.Not(check.IsNil))

node1 := newCiliumNode("node1")
mngr.Update(newCiliumNode("node1"))
mngr.Upsert(node1)
tklauser marked this conversation as resolved.
Show resolved Hide resolved

names := mngr.GetNames()
c.Assert(len(names), check.Equals, 1)
c.Assert(names[0], check.Equals, "node1")

mngr.Update(newCiliumNode("node2"))
mngr.Upsert(newCiliumNode("node2"))

names = mngr.GetNames()
c.Assert(len(names), check.Equals, 2)
Expand All @@ -97,7 +97,7 @@ func (e *ENISuite) TestNodeManagerGet(c *check.C) {
c.Assert(mngr, check.Not(check.IsNil))

node1 := newCiliumNode("node1")
mngr.Update(node1)
mngr.Upsert(node1)

c.Assert(mngr.Get("node1"), check.Not(check.IsNil))
c.Assert(mngr.Get("node2"), check.IsNil)
Expand Down Expand Up @@ -131,7 +131,7 @@ func (e *ENISuite) TestNodeManagerDefaultAllocation(c *check.C) {

// Announce node wait for IPs to become available
cn := newCiliumNode("node1", withTestDefaults(), withInstanceID(instanceID), withInstanceType("m5.large"), withIPAMPreAllocate(8))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node1")
Expand All @@ -140,7 +140,7 @@ func (e *ENISuite) TestNodeManagerDefaultAllocation(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

// Use 7 out of 8 IPs
mngr.Update(updateCiliumNode(cn, 8, 7))
mngr.Upsert(updateCiliumNode(cn, 8, 7))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node = mngr.Get("node1")
Expand Down Expand Up @@ -173,7 +173,7 @@ func (e *ENISuite) TestNodeManagerPrefixDelegation(c *check.C) {

// Announce node wait for IPs to become available
cn := newCiliumNode("node1", withInstanceID(instanceID), withInstanceType("m5a.large"), withIPAMPreAllocate(8))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node1")
Expand All @@ -182,7 +182,7 @@ func (e *ENISuite) TestNodeManagerPrefixDelegation(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

// Use 12 out of 16 IPs
mngr.Update(updateCiliumNode(cn, 16, 12))
mngr.Upsert(updateCiliumNode(cn, 16, 12))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node = mngr.Get("node1")
Expand Down Expand Up @@ -227,7 +227,7 @@ func (e *ENISuite) TestNodeManagerENIWithSGTags(c *check.C) {
}
cn := newCiliumNode("node1", withTestDefaults(), withInstanceID(instanceID), withInstanceType("m5.large"),
withSecurityGroupTags(sgTags), withIPAMPreAllocate(8))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node1")
Expand All @@ -236,7 +236,7 @@ func (e *ENISuite) TestNodeManagerENIWithSGTags(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

// Use 7 out of 8 IPs
mngr.Update(updateCiliumNode(cn, 8, 7))
mngr.Upsert(updateCiliumNode(cn, 8, 7))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node = mngr.Get("node1")
Expand Down Expand Up @@ -281,15 +281,15 @@ func (e *ENISuite) TestNodeManagerMinAllocate20(c *check.C) {

// Announce node wait for IPs to become available
cn := newCiliumNode("node2", withInstanceID(instanceID), withInstanceType("m5.4xlarge"), withIPAMPreAllocate(-1), withIPAMMinAllocate(10))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node2")
c.Assert(node, check.Not(check.IsNil))
c.Assert(node.Stats().AvailableIPs, check.Equals, 10)
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

mngr.Update(updateCiliumNode(cn, 10, 8))
mngr.Upsert(updateCiliumNode(cn, 10, 8))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)

node = mngr.Get("node2")
Expand All @@ -301,8 +301,8 @@ func (e *ENISuite) TestNodeManagerMinAllocate20(c *check.C) {
withIPAMPreAllocate(0)(cn)
withIPAMMinAllocate(20)(cn)

mngr.Update(updateCiliumNode(cn, 20, 8))
mngr.Update(cn)
mngr.Upsert(updateCiliumNode(cn, 20, 8))
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)

node = mngr.Get("node2")
Expand Down Expand Up @@ -336,7 +336,7 @@ func (e *ENISuite) TestNodeManagerMinAllocateAndPreallocate(c *check.C) {
// Announce node, wait for IPs to become available
cn := newCiliumNode("node2", withTestDefaults(), withInstanceID(instanceID), withInstanceType("m3.large"),
withIPAMPreAllocate(1), withIPAMMinAllocate(10))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node2")
Expand All @@ -345,15 +345,15 @@ func (e *ENISuite) TestNodeManagerMinAllocateAndPreallocate(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

// Use 9 out of 10 IPs, no additional IPs should be allocated
mngr.Update(updateCiliumNode(cn, 10, 9))
mngr.Upsert(updateCiliumNode(cn, 10, 9))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)
node = mngr.Get("node2")
c.Assert(node, check.Not(check.IsNil))
c.Assert(node.Stats().AvailableIPs, check.Equals, 10)
c.Assert(node.Stats().UsedIPs, check.Equals, 9)

// Use 10 out of 10 IPs, PreAllocate 1 must kick in and allocate an additional IP
mngr.Update(updateCiliumNode(cn, 10, 10))
mngr.Upsert(updateCiliumNode(cn, 10, 10))
syncTime := instances.Resync(context.TODO())
mngr.Resync(context.TODO(), syncTime)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)
Expand All @@ -363,7 +363,7 @@ func (e *ENISuite) TestNodeManagerMinAllocateAndPreallocate(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 10)

// Release some IPs, no additional IPs should be allocated
mngr.Update(updateCiliumNode(cn, 10, 8))
mngr.Upsert(updateCiliumNode(cn, 10, 8))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)
node = mngr.Get("node2")
c.Assert(node, check.Not(check.IsNil))
Expand Down Expand Up @@ -399,7 +399,7 @@ func (e *ENISuite) TestNodeManagerReleaseAddress(c *check.C) {
// Announce node, wait for IPs to become available
cn := newCiliumNode("node3", withTestDefaults(), withInstanceID(instanceID), withInstanceType("m4.xlarge"),
withIPAMPreAllocate(2), withIPAMMinAllocate(10), withIPAMMaxAboveWatermark(3))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node3", 0) }, 5*time.Second), check.IsNil)

// 10 min-allocate + 3 max-above-watermark => 13 IPs must become
Expand All @@ -410,7 +410,7 @@ func (e *ENISuite) TestNodeManagerReleaseAddress(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

// Use 11 out of 13 IPs, no additional IPs should be allocated
mngr.Update(updateCiliumNode(cn, 13, 11))
mngr.Upsert(updateCiliumNode(cn, 13, 11))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node3", 0) }, 5*time.Second), check.IsNil)
node = mngr.Get("node3")
c.Assert(node, check.Not(check.IsNil))
Expand All @@ -419,7 +419,7 @@ func (e *ENISuite) TestNodeManagerReleaseAddress(c *check.C) {

// Use 13 out of 13 IPs, PreAllocate 2 + MaxAboveWatermark 3 must kick in
// and allocate 5 additional IPs
mngr.Update(updateCiliumNode(cn, 13, 13))
mngr.Upsert(updateCiliumNode(cn, 13, 13))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node3", 0) }, 5*time.Second), check.IsNil)
node = mngr.Get("node3")
c.Assert(node, check.Not(check.IsNil))
Expand All @@ -428,7 +428,7 @@ func (e *ENISuite) TestNodeManagerReleaseAddress(c *check.C) {

// Reduce used IPs to 10, this leads to 8 excess IPs but release
// occurs at interval based resync, so expect timeout at first
mngr.Update(updateCiliumNode(cn, 18, 10))
mngr.Upsert(updateCiliumNode(cn, 18, 10))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node3", 0) }, 2*time.Second), check.Not(check.IsNil))
node = mngr.Get("node3")
c.Assert(node, check.Not(check.IsNil))
Expand Down Expand Up @@ -504,7 +504,7 @@ func (e *ENISuite) TestNodeManagerENIExcludeInterfaceTags(c *check.C) {
// Announce node wait for IPs to become available
cn := newCiliumNode("node1", withTestDefaults(), withInstanceID(instanceID), withInstanceType("m5.large"),
withExcludeInterfaceTags(map[string]string{"cilium.io/no_manage": "true"}), withIPAMPreAllocate(8))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node1")
Expand All @@ -523,7 +523,7 @@ func (e *ENISuite) TestNodeManagerENIExcludeInterfaceTags(c *check.C) {
eniNode.mutex.RUnlock()

// Use 7 out of 8 IPs
mngr.Update(updateCiliumNode(cn, 8, 7))
mngr.Upsert(updateCiliumNode(cn, 8, 7))
mngr.Resync(context.TODO(), instances.Resync(context.TODO()))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

Expand Down Expand Up @@ -565,7 +565,7 @@ func (e *ENISuite) TestNodeManagerExceedENICapacity(c *check.C) {
// Announce node, wait for IPs to become available
cn := newCiliumNode("node2", withTestDefaults(), withInstanceID(instanceID), withInstanceType("t2.xlarge"),
withIPAMPreAllocate(8), withIPAMMinAllocate(20))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node2")
Expand All @@ -576,7 +576,7 @@ func (e *ENISuite) TestNodeManagerExceedENICapacity(c *check.C) {
// Use 40 out of 42 available IPs, we should reach 0 address needed once we
// assigned the remaining 3 that the t2.xlarge instance type supports
// (3x15 - 3 = 42 max)
mngr.Update(updateCiliumNode(cn, 42, 40))
mngr.Upsert(updateCiliumNode(cn, 42, 40))
syncTime := instances.Resync(context.TODO())
mngr.Resync(context.TODO(), syncTime)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node2", 0) }, 5*time.Second), check.IsNil)
Expand Down Expand Up @@ -621,7 +621,7 @@ func (e *ENISuite) TestInterfaceCreatedInInitialSubnet(c *check.C) {
// Announce node, wait for IPs to become available
cn := newCiliumNode("node1", withTestDefaults(), withInstanceID(instanceID), withInstanceType("t2.xlarge"),
withIPAMPreAllocate(16), withNodeSubnetID(testSubnet.ID))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node1")
Expand Down Expand Up @@ -686,7 +686,7 @@ func (e *ENISuite) TestNodeManagerManyNodes(c *check.C) {
s.cn = newCiliumNode(s.name, withTestDefaults(), withInstanceID(s.instanceName), withInstanceType("c3.xlarge"),
withFirstInterfaceIndex(1), withIPAMPreAllocate(1), withIPAMMinAllocate(minAllocate))
state[i] = s
mngr.Update(s.cn)
mngr.Upsert(s.cn)
}

for _, s := range state {
Expand Down Expand Up @@ -751,7 +751,7 @@ func (e *ENISuite) TestNodeManagerInstanceNotRunning(c *check.C) {
// Announce node, ENI attachement will fail
cn := newCiliumNode("node1", withTestDefaults(), withInstanceID(instanceID), withInstanceType("m4.large"),
withFirstInterfaceIndex(1), withIPAMPreAllocate(8))
mngr.Update(cn)
mngr.Upsert(cn)

// Wait for node to be declared notRunning
c.Assert(testutils.WaitUntil(func() bool {
Expand Down Expand Up @@ -795,7 +795,7 @@ func (e *ENISuite) TestInstanceBeenDeleted(c *check.C) {
c.Assert(mngr, check.Not(check.IsNil))

cn := newCiliumNode("node1", withInstanceID(instanceID), withInstanceType("m4.large"), withIPAMPreAllocate(8))
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)

node := mngr.Get("node1")
Expand All @@ -816,7 +816,7 @@ func (e *ENISuite) TestInstanceBeenDeleted(c *check.C) {
// Resync instances from mocked AWS
instances.Resync(context.TODO())
// Use 2 out of 9 IPs
mngr.Update(updateCiliumNode(cn, 9, 2))
mngr.Upsert(updateCiliumNode(cn, 9, 2))

// Instance deletion detected, no allocation happened despite of the IP deficit.
c.Assert(node.Stats().AvailableIPs, check.Equals, 8)
Expand Down Expand Up @@ -852,7 +852,7 @@ func benchmarkAllocWorker(c *check.C, workers int64, delay time.Duration, rateLi
s.cn = newCiliumNode(s.name, withTestDefaults(), withInstanceID(s.instanceName), withInstanceType("m4.large"),
withIPAMPreAllocate(1), withIPAMMinAllocate(10))
state[i] = s
mngr.Update(s.cn)
mngr.Upsert(s.cn)
}

restart:
Expand Down
12 changes: 6 additions & 6 deletions pkg/azure/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (e *IPAMSuite) TestIpamPreAllocate8(c *check.C) {

cn := newCiliumNode("node1", "vm1", preAllocate, minAllocate)
statusRevision := k8sapi.statusRevision()
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)
// Wait for k8s status to be updated
c.Assert(testutils.WaitUntil(func() bool { return statusRevision < k8sapi.statusRevision() }, 5*time.Second), check.IsNil)
Expand All @@ -197,7 +197,7 @@ func (e *IPAMSuite) TestIpamPreAllocate8(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

// Use 7 out of 8 IPs
mngr.Update(updateCiliumNode(k8sapi.getLatestNode("node1"), toUse))
mngr.Upsert(updateCiliumNode(k8sapi.getLatestNode("node1"), toUse))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)
// Wait for k8s status to be updated
c.Assert(testutils.WaitUntil(func() bool { return statusRevision < k8sapi.statusRevision() }, 5*time.Second), check.IsNil)
Expand Down Expand Up @@ -247,7 +247,7 @@ func (e *IPAMSuite) TestIpamMinAllocate10(c *check.C) {

cn := newCiliumNode("node1", "vm1", preAllocate, minAllocate)
statusRevision := k8sapi.statusRevision()
mngr.Update(cn)
mngr.Upsert(cn)
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)
// Wait for k8s status to be updated
c.Assert(testutils.WaitUntil(func() bool { return statusRevision < k8sapi.statusRevision() }, 5*time.Second), check.IsNil)
Expand All @@ -259,7 +259,7 @@ func (e *IPAMSuite) TestIpamMinAllocate10(c *check.C) {
c.Assert(node.Stats().UsedIPs, check.Equals, 0)

// Use 7 out of 10 IPs
mngr.Update(updateCiliumNode(k8sapi.getLatestNode("node1"), toUse))
mngr.Upsert(updateCiliumNode(k8sapi.getLatestNode("node1"), toUse))
c.Assert(testutils.WaitUntil(func() bool { return reachedAddressesNeeded(mngr, "node1", 0) }, 5*time.Second), check.IsNil)
// Wait for k8s status to be updated
c.Assert(testutils.WaitUntil(func() bool { return statusRevision < k8sapi.statusRevision() }, 5*time.Second), check.IsNil)
Expand Down Expand Up @@ -319,7 +319,7 @@ func (e *IPAMSuite) TestIpamManyNodes(c *check.C) {
for i := range state {
state[i] = &nodeState{name: fmt.Sprintf("node%d", i), instanceName: fmt.Sprintf("vm%d", i)}
state[i].cn = newCiliumNode(state[i].name, state[i].instanceName, 1, minAllocate)
mngr.Update(state[i].cn)
mngr.Upsert(state[i].cn)
}

for _, s := range state {
Expand Down Expand Up @@ -395,7 +395,7 @@ func benchmarkAllocWorker(c *check.C, workers int64, delay time.Duration, rateLi
for i := range state {
state[i] = &nodeState{name: fmt.Sprintf("node%d", i), instanceName: fmt.Sprintf("vm%d", i)}
state[i].cn = newCiliumNode(state[i].name, state[i].instanceName, 1, 10)
mngr.Update(state[i].cn)
mngr.Upsert(state[i].cn)
}

restart:
Expand Down
14 changes: 0 additions & 14 deletions pkg/ip/cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ func ParsePrefixes(cidrs []string) (valid []netip.Prefix, invalid []string, erro
return valid, invalid, errors
}

// PrefixToIPNet is a convenience helper for migrating from the older 'net'
// standard library types to the newer 'netip' types. Use this to plug the
// new types in newer code into older types in older code during the migration.
func PrefixToIPNet(prefix netip.Prefix) *net.IPNet {
if !prefix.IsValid() {
return nil
}
addr := prefix.Masked().Addr()
return &net.IPNet{
IP: addr.AsSlice(),
Mask: net.CIDRMask(prefix.Bits(), addr.BitLen()),
}
}

// IPNetToPrefix is a convenience helper for migrating from the older 'net'
// standard library types to the newer 'netip' types. Use this to plug the
// new types in newer code into older types in older code during the migration.
Expand Down