diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-06-15 13:49:36 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-06-15 15:55:55 +0200 |
commit | fe488b5f11836a021bcef6217aeeea41b1321217 (patch) | |
tree | 7a90c6966811ed33636cc645d7a252d08ff04a39 /cmd/podman/pods/rm.go | |
parent | fa3b8a75c4ec571f8cbb2622ea624b42bc5c2472 (diff) | |
download | podman-fe488b5f11836a021bcef6217aeeea41b1321217.tar.gz podman-fe488b5f11836a021bcef6217aeeea41b1321217.tar.bz2 podman-fe488b5f11836a021bcef6217aeeea41b1321217.zip |
pod create --replace
Add a `--replace` flag to the `pod create` command. If another pod with
the same name already exists, it will be replaced and removed.
Adding this flag is motivated by #5485 to make running Podman in systemd
units (or any other scripts/automation) more robust. In case of a
crash, a pod may not be removed by a sytemd unit anymore. The
`--replace` flag allows for supporting crashes.
Note that the `--replace` flag does not require the `--name` flag to be
set, so it can be set unconditionally in `podman generate systemd`.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'cmd/podman/pods/rm.go')
-rw-r--r-- | cmd/podman/pods/rm.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go index 8de0bce9e..ec8dae1d1 100644 --- a/cmd/podman/pods/rm.go +++ b/cmd/podman/pods/rm.go @@ -58,24 +58,30 @@ func init() { } func rm(cmd *cobra.Command, args []string) error { - var ( - errs utils.OutputErrors - ) - ids, err := common.ReadPodIDFiles(rmOptions.PodIDFiles) if err != nil { return err } args = append(args, ids...) + return removePods(args, rmOptions.PodRmOptions, true) +} - responses, err := registry.ContainerEngine().PodRm(context.Background(), args, rmOptions.PodRmOptions) +// removePods removes the specified pods (names or IDs). Allows for sharing +// pod-removal logic across commands. +func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs bool) error { + var errs utils.OutputErrors + + responses, err := registry.ContainerEngine().PodRm(context.Background(), namesOrIDs, rmOptions) if err != nil { return err } + // in the cli, first we print out all the successful attempts for _, r := range responses { if r.Err == nil { - fmt.Println(r.Id) + if printIDs { + fmt.Println(r.Id) + } } else { errs = append(errs, r.Err) } |