fix(network): make address selection deterministic across layers#22043
Open
iyiguncevik wants to merge 3 commits intojuju:4.0from
Open
fix(network): make address selection deterministic across layers#22043iyiguncevik wants to merge 3 commits intojuju:4.0from
iyiguncevik wants to merge 3 commits intojuju:4.0from
Conversation
c3e8390 to
f291c1c
Compare
f291c1c to
fa252d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes non-deterministic address selection by making scope-based
matching deterministic and by clarifying layer responsibilities between network
state and service code.
The issue is that callers often select the first matching address; when
candidate order is unstable, selected addresses can vary across runs.
What changed:
core/network/address.go: UpdatedSpaceAddresses.AllMatchingScopeto return deterministically sorted matches —this is the most important change.domain/network/service/unitaddress.go: GetUnitPrivateAddress now:domain/network/state/unitinfo.go+domain/network/service/unitinfo.go:domain/status/state/model/modelstate.go—no change. It is intentionally left unchanged in this PR becauseGetMachineFullStatusescurrently has downstream expectations on that shape/contract, so “fixing” it here would break expected behavior.Checklist
Integration tests, with comments saying what you're testingdoc.go added or updated in changed packagesQA steps
Setup network interfaces:
❯ lxc network create lxdbr1 \ ipv4.address=10.155.6.1/24 \ ipv4.nat=true \ ipv6.address=none ❯ lxc network create lxdbr2 \ ipv4.address=10.155.2.1/24 \ ipv4.nat=true \ ipv6.address=none ❯ lxc network create lxdbr3 \ ipv4.address=10.155.3.1/24 \ ipv4.nat=true \ ipv6.address=none ❯ lxc network list ❯ lxc profile device add default eth1 nic \ network=lxdbr1 name=eth1 ❯ lxc profile device add default eth2 nic \ network=lxdbr2 name=eth2 ❯ lxc profile device add default eth3 nic \ network=lxdbr3 name=eth3 ❯ lxc profile show default | yq '.devices' eth0: name: eth0 network: lxdbr0 type: nic eth1: name: eth1 network: lxdbr1 type: nic eth2: name: eth2 network: lxdbr2 type: nic eth3: name: eth3 network: lxdbr3 type: nic root: path: / pool: default type: disk ❯ juju bootstrap lxd srcVerify IP addresses
Documentation changes
Links
Issue: Fixes #21809
Jira card: JUJU-9244