Skip to content

Move to deterministic network setup order#28275

Merged
Luap99 merged 2 commits into
podman-container-tools:mainfrom
mheon:ordered_networks
Apr 20, 2026
Merged

Move to deterministic network setup order#28275
Luap99 merged 2 commits into
podman-container-tools:mainfrom
mheon:ordered_networks

Conversation

@mheon

@mheon mheon commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

This was implemented by containers/netavark #1369; this commit completes the process by wiring it into Podman. We now respect the CLI order for configured networks - if a user passes --net net1,net2 we guarantee that net1 will be configured before net2.

For containers created before this patch, we don't retain enough information to configure networks in CLI order, so we use alphabetical order instead to still guarantee consistency.

No breaking API changes have been made, but we do add a new field to supplement the existing map to (optionally) provide ordering information. The Podman CLI will always pass this. Existing applications that do not will, again, receive] deterministic ordering based on an alphabetical sort of network names.

Draft as this required Buildah and c/common changes be merged first. Also requires a new Netavark in our CI VMs; I have a hack in there to build from source right now.

Does this PR introduce a user-facing change?

Containers in multiple networks now have these networks configured in a deterministic order based on the order they were passed on the command line.

@mheon mheon marked this pull request as draft March 12, 2026 15:29
@github-actions github-actions Bot added the kind/api-change Change to remote API; merits scrutiny label Mar 12, 2026
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 559ea39. @lsm5, @psss, @thrix please check.

@mheon mheon force-pushed the ordered_networks branch from 559ea39 to dc79633 Compare March 12, 2026 15:47
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit dc79633. @lsm5, @psss, @thrix please check.

@mheon mheon added the bloat_approved Approve a PR in which binary file size grows by over 50k label Mar 12, 2026
@packit-as-a-service

Copy link
Copy Markdown

Cockpit tests failed for commit dc79633. @martinpitt, @jelly, @mvollmer please check.

Comment thread libpod/sqlite_state.go
@mheon mheon force-pushed the ordered_networks branch from dc79633 to e8cecc1 Compare March 18, 2026 17:22
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit e8cecc1. @lsm5, @psss, @thrix please check.

@packit-as-a-service

Copy link
Copy Markdown

Cockpit tests failed for commit e8cecc1. @martinpitt, @jelly, @mvollmer please check.

@mheon mheon force-pushed the ordered_networks branch from e8cecc1 to 7374fa3 Compare March 19, 2026 14:40
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 7374fa3. @lsm5, @psss, @thrix please check.

@packit-as-a-service

Copy link
Copy Markdown

Cockpit tests failed for commit 7374fa3. @martinpitt, @jelly, @mvollmer please check.

@mheon mheon force-pushed the ordered_networks branch from 7374fa3 to 136a428 Compare March 23, 2026 12:44
@packit-as-a-service

Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

1 similar comment
@packit-as-a-service

Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@mheon mheon force-pushed the ordered_networks branch from 136a428 to 7aa0d2f Compare March 23, 2026 14:46
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 7aa0d2f. @lsm5, @psss, @thrix please check.

@packit-as-a-service

Copy link
Copy Markdown

Cockpit tests failed for commit 7aa0d2f. @martinpitt, @jelly, @mvollmer please check.

@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit a267d1d. @lsm5, @psss, @thrix please check.

@packit-as-a-service

Copy link
Copy Markdown

Cockpit tests failed for commit a267d1d. @martinpitt, @jelly, @mvollmer please check.

@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 9bab3e8. @lsm5, @psss, @thrix please check.

@mheon mheon force-pushed the ordered_networks branch from 9bab3e8 to 704a026 Compare March 25, 2026 08:51
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 704a026. @lsm5, @psss, @thrix please check.

@packit-as-a-service

Copy link
Copy Markdown

Cockpit tests failed for commit 704a026. @martinpitt, @jelly, @mvollmer please check.

@mheon mheon force-pushed the ordered_networks branch from 704a026 to 3bcff06 Compare March 25, 2026 14:10
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 3bcff06. @lsm5, @psss, @thrix please check.


# Absurd sed oneliner provided by Google Gemini
local ctrname=ctr-$(safename)
run_podman run --name $ctrname --net "$netname1:interface_name=first" --net "$netname2:interface_name=second" $IMAGE sh -c "ip link | sed -nE 's/^([0-9]+): ([^:]+):.*/\1 \2/p' | sed 's/@.*//'"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

something like

run_podman run ... quay.io/libpod/testimage:20241011 ip -j link
run -0 jq -r '.[] | (.ifindex|tostring) + " "  + .ifname' <<<"$output"
assert ...

might be cleaner and actually understandable what is being parsed compared to the regex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you don't mind I'd prefer to leave as-is and avoid the stacked run calls - maybe I could add a comment indicating what the Sed bit does?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't care to much, I just fine reading jq language much easier than regex

@mheon mheon force-pushed the ordered_networks branch from 6b46a51 to 5a6020c Compare April 16, 2026 13:57
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 5a6020c. @lsm5, @psss, @thrix please check.

Comment thread libpod/sqlite_state_internal.go Outdated
} else {
delete(newCfg.Networks, network)
// Modifying an existing network, modify existing array in place
index := slices.IndexFunc(newCfg.Networks, finderFunc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my point was more than you do the IndexFunc once where you call ContainsFunc(), and then instead of ok you match index >= 0 so we do not need to iterate the slice multiple times.
At the vey least this makes it obvious that IndexFunc() must return a valid match here, because a naive reader could ask what happens if there is no match and we then index -1 int he slice and panic.

but sure not to important right now, though lint complains and wants a switch here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I can see that being a better solution, I'll do it

@mheon mheon force-pushed the ordered_networks branch from 5a6020c to 378b1f5 Compare April 16, 2026 14:40
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 378b1f5. @lsm5, @psss, @thrix please check.

@mheon mheon force-pushed the ordered_networks branch from 378b1f5 to d1408b6 Compare April 17, 2026 12:21
@mheon mheon marked this pull request as ready for review April 17, 2026 12:21
@mheon mheon changed the title DRAFT: Move to deterministic network setup order Move to deterministic network setup order Apr 17, 2026
@mheon

mheon commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

c/common and Buildah merged, ready for review + merge

@Luap99 Luap99 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Luap99

Luap99 commented Apr 17, 2026

Copy link
Copy Markdown
Member

@containers/podman-maintainers PTAL

@mheon mheon force-pushed the ordered_networks branch from d1408b6 to e1a1119 Compare April 17, 2026 12:26
@packit-as-a-service

Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

1 similar comment
@packit-as-a-service

Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@mheon mheon force-pushed the ordered_networks branch from e1a1119 to 3112433 Compare April 17, 2026 13:24
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 3112433. @lsm5, @psss, @thrix please check.

Networks map[string]types.PerNetworkOptions `json:"newNetworks,omitempty"`
Networks []types.NamedPerNetworkOptions `json:"orderedNetworks,omitempty"`
// LegacyNetworks is deprecated and should not be used.
// It is identify to Networks aside from being unordered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be here, depreciation notice? https://go.dev/wiki/Deprecated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean this is internal code which we do not support externally, if we call it deprecated we must //nolint the callers who still need so I doubt it matters.

@Honny1 Honny1 Apr 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, my idea was to avoid accidental usage in the future. Even though it's just internal.

opts.Networks = map[string]types.PerNetworkOptions{
netName: networks[netName],

for _, net := range networks {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is the second search of the same network.

// this value is only used for container create.
// Added in podman 4.0, previously NetworksDeprecated was used. Make
// Added in podman 6.0, previously LegacyNetworks was used. Make
// sure to not change the json tags.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be removed or moved to LegacyNetworks.

@Honny1

Honny1 commented Apr 17, 2026

Copy link
Copy Markdown
Contributor
libpod/sqlite_state_internal.go:657:1: File is not properly formatted (gofumpt)
		keys := make([]string, 0, len(legacyNetworks))
^
1 issues:

mheon added 2 commits April 17, 2026 10:00
This was implemented by containers/netavark podman-container-tools#1369; this commit
completes the process by wiring it into Podman. We now respect
the CLI order for configured networks - if a user passes
`--net net1,net2` we guarantee that net1 will be configured
before net2.

For containers created before this patch, we don't retain enough
information to configure networks in CLI order, so we use
alphabetical order instead to still guarantee consistency.

No breaking API changes have been made, but we do add a new
field to supplement the existing map to (optionally) provide
ordering information. The Podman CLI will always pass this.
Existing applications that do not will, again, receive]
deterministic ordering based on an alphabetical sort of network
names.

This requires the latest version of Netavark to work properly.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
These are two new Buildah flags that we need to wire into Podman
(both local and remote) and document, with the interesting note
that one requires the other and a check needed to be added for
that.

Also: secret parsing was tightened up in Buildah, and was
breaking the remote build tests. Rewire it to use the new parser
Buildah made, which ends up simplifying the code considerably.
Tests are back to passing afterwards.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
@mheon mheon force-pushed the ordered_networks branch from 3112433 to efba999 Compare April 17, 2026 14:45
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit efba999. @lsm5, @psss, @thrix please check.

@Luap99 Luap99 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, I am going to merge this unblock the vendoring for others, we can fix up some minor comments from @Honny1 later

@Luap99 Luap99 merged commit 34a4633 into podman-container-tools:main Apr 20, 2026
89 of 91 checks passed
@Honny1

Honny1 commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Should I take care of that fix, or is @mheon doing it? I just don't want to forget about it. Let me know.

@Luap99

Luap99 commented Apr 20, 2026

Copy link
Copy Markdown
Member

I would assume @mheon should do the work but I let you sync on that, I guess he won't mind if you do it.

Luap99 added a commit that referenced this pull request Apr 23, 2026
Cleanup from deterministic network order PR #28275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bloat_approved Approve a PR in which binary file size grows by over 50k kind/api-change Change to remote API; merits scrutiny machine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants