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 <mheon@redhat.com>
This commit is contained in:
Matt Heon
2025-12-04 15:25:11 -05:00
parent 244aa643c7
commit a8ecb80ac0
2 changed files with 14 additions and 0 deletions

View File

@@ -6,6 +6,9 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"slices"
"sort"
"strings"
"github.com/containers/podman/v6/libpod/define" "github.com/containers/podman/v6/libpod/define"
"github.com/containers/podman/v6/libpod/events" "github.com/containers/podman/v6/libpod/events"
@@ -620,6 +623,8 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
ctrStatuses[c.ID()] = c.state.State 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) podState, err := createPodStatusResults(ctrStatuses)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -641,6 +646,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
sharesNS = append(sharesNS, nsStr) sharesNS = append(sharesNS, nsStr)
} }
} }
sort.Strings(sharesNS)
// Infra config contains detailed information on the pod's infra // Infra config contains detailed information on the pod's infra
// container. // container.

View File

@@ -807,4 +807,12 @@ function thingy_with_unique_id() {
done 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 # vim: filetype=sh