Files
podman/libpod/pod_status.go
Miloslav Trmač 4c3027c149 Make most of libpod, and everything that relies on it, non-darwin
Require (linux || freebsd), because the code already does that, in practice.
This just means macOS users of IDEs aren't hit with thousands of compilation
errors (and then the IDE can open an Linux-specific file and then process it
under the Linux assumption, which works much better).

This commit ONLY replaces
	//go:build !remote
with
	//go:build !remote && (linux || freebsd)

and is split from the rest to allow mechanically verifying that fact,
and focusing a review on the other kinds of changes.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2026-02-27 22:18:36 +01:00

64 lines
1.8 KiB
Go

//go:build !remote && (linux || freebsd)
package libpod
import "github.com/containers/podman/v6/libpod/define"
// GetPodStatus determines the status of the pod based on the
// statuses of the containers in the pod.
// Returns a string representation of the pod status
func (p *Pod) GetPodStatus() (string, error) {
ctrStatuses, err := p.Status()
if err != nil {
return define.PodStateErrored, err
}
return createPodStatusResults(ctrStatuses)
}
func createPodStatusResults(ctrStatuses map[string]define.ContainerStatus) (string, error) {
ctrNum := len(ctrStatuses)
if ctrNum == 0 {
return define.PodStateCreated, nil
}
statuses := map[string]int{
define.PodStateStopped: 0,
define.PodStateRunning: 0,
define.PodStatePaused: 0,
define.PodStateCreated: 0,
define.PodStateErrored: 0,
}
for _, ctrStatus := range ctrStatuses {
switch ctrStatus {
case define.ContainerStateExited:
fallthrough
case define.ContainerStateStopped:
statuses[define.PodStateStopped]++
case define.ContainerStateRunning:
statuses[define.PodStateRunning]++
case define.ContainerStatePaused:
statuses[define.PodStatePaused]++
case define.ContainerStateCreated, define.ContainerStateConfigured:
statuses[define.PodStateCreated]++
default:
statuses[define.PodStateErrored]++
}
}
switch {
case statuses[define.PodStateRunning] == ctrNum:
return define.PodStateRunning, nil
case statuses[define.PodStateRunning] > 0:
return define.PodStateDegraded, nil
case statuses[define.PodStatePaused] == ctrNum:
return define.PodStatePaused, nil
case statuses[define.PodStateStopped] == ctrNum:
return define.PodStateExited, nil
case statuses[define.PodStateStopped] > 0:
return define.PodStateStopped, nil
case statuses[define.PodStateErrored] > 0:
return define.PodStateErrored, nil
default:
return define.PodStateCreated, nil
}
}