diff --git a/pkg/octavia/network_parameters.go b/pkg/octavia/network_parameters.go index 393535cd..27a7cbe7 100644 --- a/pkg/octavia/network_parameters.go +++ b/pkg/octavia/network_parameters.go @@ -50,9 +50,15 @@ func getConfigFromNAD( return nadConfig, nil } +// getRangeFromCIDR - compute a IP address range from a CIDR func getRangeFromCIDR( cidr netip.Prefix, ) (start netip.Addr, end netip.Addr) { + // For IPv6, a /64 is expected, if the CIDR is aaaa:bbbb:cccc:dddd::/64, + // the range is aaaa:bbbb:cccc:dddd::5 - aaaa:bbbb:cccc:dddd:ffff:ffff:ffff:fffe + // For IPv4, a /16 is expected, if the CIDR is a.b.0.0/16 + // the range is a.b.0.5 - a.b.255.254 + // IPs from from 1 to 5 are reserved for later user addr := cidr.Addr() if addr.Is6() { addrBytes := addr.As16() @@ -78,6 +84,7 @@ func getRangeFromCIDR( return } +// GetNetworkParametersFromNAD - Extract network information from the Network Attachment Definition func GetNetworkParametersFromNAD( nad *networkv1.NetworkAttachmentDefinition, ) (*NetworkParameters, error) { @@ -89,8 +96,14 @@ func GetNetworkParametersFromNAD( } // Provider subnet parameters + // These are the parameters for octavia-provider-net/subnet networkParameters.ProviderCIDR = nadConfig.IPAM.CIDR + // OpenShift allocates IP addresses from IPAM.RangeStart to IPAM.RangeEnd + // for the pods. + // We're going to use a range of 25 IP addresses that are assigned to + // the Neutron allocation pool, the range starts right after OpenShift + // RangeEnd. networkParameters.ProviderAllocationStart = nadConfig.IPAM.RangeEnd.Next() end := networkParameters.ProviderAllocationStart for i := 0; i < LbProvSubnetPoolSize; i++ { @@ -100,14 +113,21 @@ func GetNetworkParametersFromNAD( end = end.Next() } networkParameters.ProviderAllocationEnd = end + + // The default gateway of the provider network is the gateway of our route if len(nadConfig.IPAM.Routes) > 0 { networkParameters.ProviderGateway = nadConfig.IPAM.Routes[0].Gateway } else { return nil, fmt.Errorf("cannot find gateway information in network attachment") } - // Tenant subnet parameters + // Tenant subnet parameters - parameters for lb-mgmt-net/subnet + // The NAD must contain one route to the Octavia Tenant Management network, + // the gateway is an IP address of the provider network and the destination + // is the CIDR of the Tenant network. networkParameters.TenantCIDR = nadConfig.IPAM.Routes[0].Destination + + // For IPv4, we require a /16 subnet, for IPv6 a /64 var bitlen int if networkParameters.TenantCIDR.Addr().Is6() { bitlen = 64 @@ -119,6 +139,7 @@ func GetNetworkParametersFromNAD( return nil, fmt.Errorf("the tenant CIDR is /%d, it should be /%d", networkParameters.TenantCIDR.Bits(), bitlen) } + // Compute an allocation range based on the CIDR start, end := getRangeFromCIDR(networkParameters.TenantCIDR) networkParameters.TenantAllocationStart = start networkParameters.TenantAllocationEnd = end