Skip to content

Conversation

@nmezhenskyi
Copy link
Contributor

@nmezhenskyi nmezhenskyi commented Aug 6, 2025

This PR adds support for internal OVN load balancers and network forwards, enabling the use of internal OVN IPs as a listen address.

Changes:

  • Updated GetProjectNetworkLoadBalancerListenAddressesByUplink() and GetProjectNetworkForwardListenAddressesByUplink() functions to skip listen addresses that are internal OVN IPs. This is needed for the following functions to work correctly with the introduction of internal load balancers and network forwards:

func (n *common) validateRoutes(config map[string]string) error {

func (n *common) getExternalSubnetInUse(ctx context.Context, tx *db.ClusterTx, uplinkNetworkName string, memberSpecific bool) ([]externalSubnetUsage, error) {

func UplinkAddressQuotasExceeded(ctx context.Context, tx *db.ClusterTx, projectName string, networkName string, uplinkIPV4Quota int, uplinkIPV6Quota int, projectNetworks map[int64]api.Network) (V4QuotaExceeded bool, V6QuotaExceeded bool, err error) {

  • Updated allocateUplinkAddress() function for OVN networks to allow allocating internal OVN IPs for load balancers and network forwards.

  • Added checkInternalAddressNotInUse() function for OVN networks to validate internal OVN IPs before allocation.

@nmezhenskyi nmezhenskyi marked this pull request as draft August 6, 2025 14:50
Comment on lines 277 to 294
SELECT
projects.name,
networks.name,
networks_load_balancers.listen_address
networks.type,
networks_load_balancers.listen_address,
nc_ipv4.value AS ipv4_address,
nc_ipv6.value AS ipv6_address
FROM networks_load_balancers
JOIN networks on networks.id = networks_load_balancers.network_id
JOIN networks_config on networks.id = networks_config.network_id
JOIN networks ON networks.id = networks_load_balancers.network_id
JOIN projects ON projects.id = networks.project_id
JOIN networks_config AS nc_filter on networks.id = nc_filter.network_id
LEFT JOIN networks_config AS nc_ipv4 ON networks.id = nc_ipv4.network_id AND nc_ipv4.key = 'ipv4.address'
LEFT JOIN networks_config AS nc_ipv6 ON networks.id = nc_ipv6.network_id AND nc_ipv6.key = 'ipv6.address'
WHERE (
(networks_config.key = "network" AND networks_config.value = ?1)
(nc_filter.key = "network" AND nc_filter.value = ?1)
OR (projects.name = "default" AND networks.name = ?1)
)
`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query is used in:

func (n *common) validateRoutes(config map[string]string) error {

func (n *common) getExternalSubnetInUse(ctx context.Context, tx *db.ClusterTx, uplinkNetworkName string, memberSpecific bool) ([]externalSubnetUsage, error) {

func UplinkAddressQuotasExceeded(ctx context.Context, tx *db.ClusterTx, projectName string, networkName string, uplinkIPV4Quota int, uplinkIPV6Quota int, projectNetworks map[int64]api.Network) (V4QuotaExceeded bool, V6QuotaExceeded bool, err error) {

In all these contexts, it is safe to omit listen addresses that are internal OVN IPs.

But alternatively, I can add an additional bool parameter (i.e., externalOnly) to the GetProjectNetworkLoadBalancerListenAddressesByUplink() function signature to explicitly determine whether internal listen addresses should be filtered out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least you should update the function's comment to explain it I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll update it

@nmezhenskyi nmezhenskyi force-pushed the ovn-lb-internal branch 4 times, most recently from 7920bdd to 6e7dc46 Compare August 7, 2025 20:18
…isten addresses by uplink

Update the `GetProjectNetworkLoadBalancerListenAddressesByUplink()`
function to skip the listen addresses that are internal OVN IPs.
Internal OVN IPs are not dependent on the uplink's IP routes.

Signed-off-by: Nikita Mezhenskyi <[email protected]>
…addresses by uplink

Update the `GetProjectNetworkForwardListenAddressesByUplink()`
function to skip the listen addresses that are internal OVN IPs.
Internal OVN IPs are not dependent on the uplink's IP routes.

Signed-off-by: Nikita Mezhenskyi <[email protected]>
…balancers

Allow using internal OVN IP as a listen address for OVN network forwards
and load balancers. Ensure proper validation for internal OVN IPs used
as listen addresses.

Signed-off-by: Nikita Mezhenskyi <[email protected]>
@nmezhenskyi nmezhenskyi marked this pull request as ready for review August 7, 2025 21:04
@nmezhenskyi nmezhenskyi requested a review from tomponline August 7, 2025 21:04
@nmezhenskyi nmezhenskyi changed the title Network: Internal OVN load balancers and forwards (WIP) Network: Internal OVN load balancers and forwards Aug 7, 2025
return true, fmt.Errorf("Listen address %q is already in use by %q of network %q", listenAddress, netIPKey, n.name)
}

var forwards map[int64]string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tip:

var forwards, loadBalancers map[int64]string

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

Things to follow up on:

  1. Add functional tests to lxd-ci for internal load balancers and forwarders (in addition to the thorough validation logic tests youve added here).
  2. Update docs with mention of this capability - please also add an API extension to document programatically this new capability.
  3. Address minor comments in PR.

@tomponline tomponline merged commit 2382b99 into canonical:main Aug 8, 2025
31 checks passed
tomponline added a commit to canonical/lxd-ci that referenced this pull request Aug 13, 2025
This PR adds tests to check that internal load balancers and forwards
are reachable from inside of the OVN network, but are unreachable from
outside.

Follow-up to canonical/lxd#16162.

This should be merged together with
canonical/lxd#16179 (adds
`ovn_internal_load_balancer` API extension for LXD).
tomponline added a commit that referenced this pull request Aug 18, 2025
Follow-up to #16162.

## Changes:
- Updated the documentation with mention of ability to use internal IPs
for OVN load balancers and network forwards.
- Added API extension `ovn_internal_load_balancer`.
- Addressed code improvement comments from the original PR.
@nmezhenskyi nmezhenskyi deleted the ovn-lb-internal branch September 15, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants