diff options
author | Peter Hunt <pehunt@redhat.com> | 2019-03-15 17:41:03 -0400 |
---|---|---|
committer | Peter Hunt <pehunt@redhat.com> | 2019-04-16 11:23:18 -0400 |
commit | 0b34b4a59cf090a47a2a13cc4814954c497b3d49 (patch) | |
tree | 22e5185775ae83766d6911dd6b3d6b8376a976e1 /cmd/podman/shared/pod.go | |
parent | a2e9626d92dedb182a500c3a0f04dcc0499a6d54 (diff) | |
download | podman-0b34b4a59cf090a47a2a13cc4814954c497b3d49.tar.gz podman-0b34b4a59cf090a47a2a13cc4814954c497b3d49.tar.bz2 podman-0b34b4a59cf090a47a2a13cc4814954c497b3d49.zip |
Add podman pod prune
podman system prune would leave pods be, and not prune them if they were stopped.
Fix this by adding a `podman pod prune` command that prunes stopped pods similarly to containers.
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'cmd/podman/shared/pod.go')
-rw-r--r-- | cmd/podman/shared/pod.go | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/cmd/podman/shared/pod.go b/cmd/podman/shared/pod.go index 4d936d61c..3f4cb0312 100644 --- a/cmd/podman/shared/pod.go +++ b/cmd/podman/shared/pod.go @@ -10,12 +10,12 @@ import ( ) const ( - stopped = "Stopped" - running = "Running" - paused = "Paused" - exited = "Exited" - errored = "Error" - created = "Created" + PodStateStopped = "Stopped" + PodStateRunning = "Running" + PodStatePaused = "Paused" + PodStateExited = "Exited" + PodStateErrored = "Error" + PodStateCreated = "Created" ) // GetPodStatus determines the status of the pod based on the @@ -24,7 +24,7 @@ const ( func GetPodStatus(pod *libpod.Pod) (string, error) { ctrStatuses, err := pod.Status() if err != nil { - return errored, err + return PodStateErrored, err } return CreatePodStatusResults(ctrStatuses) } @@ -32,44 +32,44 @@ func GetPodStatus(pod *libpod.Pod) (string, error) { func CreatePodStatusResults(ctrStatuses map[string]libpod.ContainerStatus) (string, error) { ctrNum := len(ctrStatuses) if ctrNum == 0 { - return created, nil + return PodStateCreated, nil } statuses := map[string]int{ - stopped: 0, - running: 0, - paused: 0, - created: 0, - errored: 0, + PodStateStopped: 0, + PodStateRunning: 0, + PodStatePaused: 0, + PodStateCreated: 0, + PodStateErrored: 0, } for _, ctrStatus := range ctrStatuses { switch ctrStatus { case libpod.ContainerStateExited: fallthrough case libpod.ContainerStateStopped: - statuses[stopped]++ + statuses[PodStateStopped]++ case libpod.ContainerStateRunning: - statuses[running]++ + statuses[PodStateRunning]++ case libpod.ContainerStatePaused: - statuses[paused]++ + statuses[PodStatePaused]++ case libpod.ContainerStateCreated, libpod.ContainerStateConfigured: - statuses[created]++ + statuses[PodStateCreated]++ default: - statuses[errored]++ + statuses[PodStateErrored]++ } } - if statuses[running] > 0 { - return running, nil - } else if statuses[paused] == ctrNum { - return paused, nil - } else if statuses[stopped] == ctrNum { - return exited, nil - } else if statuses[stopped] > 0 { - return stopped, nil - } else if statuses[errored] > 0 { - return errored, nil + if statuses[PodStateRunning] > 0 { + return PodStateRunning, nil + } else if statuses[PodStatePaused] == ctrNum { + return PodStatePaused, nil + } else if statuses[PodStateStopped] == ctrNum { + return PodStateExited, nil + } else if statuses[PodStateStopped] > 0 { + return PodStateStopped, nil + } else if statuses[PodStateErrored] > 0 { + return PodStateErrored, nil } - return created, nil + return PodStateCreated, nil } // GetNamespaceOptions transforms a slice of kernel namespaces |