Skip to content

Commit 6b207c9

Browse files
committed
azure: Pick the last IP in the subnet
Picking the last IP in the subnet for the internal LBIP. Previously, the 5th IP was being picked due to reservations for the first few IPs but if the users reserver more of the IPs at the start, the LBIP logic will not work. Choosing the last IP now to reduce the chances for error.
1 parent 7b227fa commit 6b207c9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/asset/manifests/azure/cluster.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,14 @@ func getIPWithinCIDR(subnets []*net.IPNet, ip string) string {
331331
return ip
332332
}
333333
}
334-
ipSubnets := make(net.IP, len(subnets[0].IP))
335-
copy(ipSubnets, subnets[0].IP)
336-
// Since the first 4 IP of the subnets are usually reserved[1], pick the next one that's available in the CIDR.
337-
// [1] - https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/private-ip-addresses#allocation-method
338-
ipSubnets[len(ipSubnets)-1] += 4
339-
return ipSubnets.String()
334+
335+
// Pick the last IP address in the first subnet range using the mask.
336+
subnet := *subnets[0]
337+
lastIP := make(net.IP, len(subnet.Mask))
338+
for i := range subnet.IP {
339+
lastIP[i] = subnet.IP[i] | (subnet.Mask[i] ^ 0xFF)
340+
}
341+
return lastIP.String()
340342
}
341343

342344
func getNextAvailableIPForLoadBalancer(ctx context.Context, installConfig *installconfig.InstallConfig, lbip string) (string, error) {

0 commit comments

Comments
 (0)