From a8ecb80ac07f4b6e61687a3a4b307194acdff41e Mon Sep 17 00:00:00 2001 From: Matt Heon Date: Thu, 4 Dec 2025 15:25:11 -0500 Subject: [PATCH] Deterministically order pod inspect fields There are two fields I'm worried about: shared namespaces and pod containers. Both are generated via loops over maps and are thus non-deterministic in ordering. Throw a sort on each to fix the order so we can actually diff `podman pod inspect` output. Signed-off-by: Matt Heon --- libpod/pod_api.go | 6 ++++++ test/system/200-pod.bats | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/libpod/pod_api.go b/libpod/pod_api.go index 6872db01c5..d8fd64ac48 100644 --- a/libpod/pod_api.go +++ b/libpod/pod_api.go @@ -6,6 +6,9 @@ import ( "context" "errors" "fmt" + "slices" + "sort" + "strings" "github.com/containers/podman/v6/libpod/define" "github.com/containers/podman/v6/libpod/events" @@ -620,6 +623,8 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) { ctrStatuses[c.ID()] = c.state.State } } + slices.SortFunc(ctrs, func(a, b define.InspectPodContainerInfo) int { return strings.Compare(a.ID, b.ID) }) + podState, err := createPodStatusResults(ctrStatuses) if err != nil { return nil, err @@ -641,6 +646,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) { sharesNS = append(sharesNS, nsStr) } } + sort.Strings(sharesNS) // Infra config contains detailed information on the pod's infra // container. diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats index f59223cd25..c4bf92305f 100644 --- a/test/system/200-pod.bats +++ b/test/system/200-pod.bats @@ -807,4 +807,12 @@ function thingy_with_unique_id() { done } +@test "podman pod inspect ordering" { + local pod_name="p-$(safename)" + run_podman pod create $pod_name + + run_podman pod inspect --format '{{ .SharedNamespaces }}' $pod_name + assert "$output" == "[ipc net uts]" +} + # vim: filetype=sh