From a0c9be20617a871c6cb61f27516565af36338d7a Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 28 Nov 2018 12:24:14 -0500 Subject: Add --sync option to podman rm With the changes made recently to ensure Podman does not hit the OCI runtime as often to sync state, we can find ourselves in a situation where the runtime's state does not match ours. Add a --sync flag to podman rm to ensure we can still remove containers when this happens. Signed-off-by: Matthew Heon --- cmd/podman/rm.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cmd/podman') diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go index 7c0569b78..224df4543 100644 --- a/cmd/podman/rm.go +++ b/cmd/podman/rm.go @@ -20,6 +20,10 @@ var ( Usage: "Force removal of a running container. The default is false", }, LatestFlag, + cli.BoolFlag{ + Name: "sync", + Usage: "Sync container state with OCI runtime before removing", + }, cli.BoolFlag{ Name: "volumes, v", Usage: "Remove the volumes associated with the container (Not implemented yet)", @@ -73,6 +77,12 @@ func rmCmd(c *cli.Context) error { for _, container := range delContainers { con := container f := func() error { + if c.Bool("sync") { + if err := con.Sync(); err != nil { + return err + } + } + return runtime.RemoveContainer(ctx, con, c.Bool("force")) } -- cgit v1.2.3-54-g00ecf From 28bead8be8eb541cf0c78e6ee3a3963adc8d1d3a Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 28 Nov 2018 12:48:58 -0500 Subject: Add --sync flag to podman ps The previous commit added support for --sync to podman rm to ensure state inconsistencies would not prevent containers from being removed. Add the flag to podman ps as well, so that all containers can be forcibly synced and all state inconsistencies resolved. Signed-off-by: Matthew Heon --- cmd/podman/ps.go | 5 +++++ cmd/podman/shared/container.go | 7 +++++++ completions/bash/podman | 1 + docs/podman-ps.1.md | 7 +++++++ docs/podman-rm.1.md | 2 +- 5 files changed, 21 insertions(+), 1 deletion(-) (limited to 'cmd/podman') diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go index 0b03388a2..7a4a80769 100644 --- a/cmd/podman/ps.go +++ b/cmd/podman/ps.go @@ -200,6 +200,10 @@ var ( Usage: "Sort output by command, created, id, image, names, runningfor, size, or status", Value: "created", }, + cli.BoolFlag{ + Name: "sync", + Usage: "Sync container state with OCI runtime", + }, } psDescription = "Prints out information about the containers" psCommand = cli.Command{ @@ -260,6 +264,7 @@ func psCmd(c *cli.Context) error { Size: c.Bool("size"), Namespace: c.Bool("namespace"), Sort: c.String("sort"), + Sync: c.Bool("sync"), } filters := c.StringSlice("filter") diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go index d0e892961..90ce193f7 100644 --- a/cmd/podman/shared/container.go +++ b/cmd/podman/shared/container.go @@ -45,6 +45,7 @@ type PsOptions struct { Sort string Label string Namespace bool + Sync bool } // BatchContainerStruct is the return obkect from BatchContainer and contains @@ -126,6 +127,12 @@ func NewBatchContainer(ctr *libpod.Container, opts PsOptions) (PsContainerOutput pso PsContainerOutput ) batchErr := ctr.Batch(func(c *libpod.Container) error { + if opts.Sync { + if err := c.Sync(); err != nil { + return err + } + } + conState, err = c.State() if err != nil { return errors.Wrapf(err, "unable to obtain container state") diff --git a/completions/bash/podman b/completions/bash/podman index 21d35949d..1c21ab3d9 100644 --- a/completions/bash/podman +++ b/completions/bash/podman @@ -2038,6 +2038,7 @@ _podman_ps() { --quiet -q --size -s --namespace --ns + --sync " _complete_ "$options_with_args" "$boolean_options" } diff --git a/docs/podman-ps.1.md b/docs/podman-ps.1.md index 7333a1095..8b86703d8 100644 --- a/docs/podman-ps.1.md +++ b/docs/podman-ps.1.md @@ -103,6 +103,13 @@ Valid filters are listed below: Print usage statement +**--sync** + +Force a sync of container state with the OCI runtime. +In some cases, a container's state in the runtime can become out of sync with Podman's state. +This will update Podman's state based on what the OCI runtime reports. +Forcibly syncing is much slower, but can resolve inconsistent state issues. + ## EXAMPLES ``` diff --git a/docs/podman-rm.1.md b/docs/podman-rm.1.md index 7f22113ea..57274c523 100644 --- a/docs/podman-rm.1.md +++ b/docs/podman-rm.1.md @@ -26,7 +26,7 @@ to run containers such as CRI-O, the last started container could be from either **--sync** -Force a sync of container state with the OCI runtime before attempting to remove. +Force a sync of container state with the OCI runtime before attempting to remove the container. In some cases, a container's state in the runtime can become out of sync with Podman's state, which can cause Podman to refuse to remove containers because it believes they are still running. A sync will resolve this issue. -- cgit v1.2.3-54-g00ecf From e5335fd74c7ed6fe0fa55bf33afbdab23ed687f1 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 5 Dec 2018 09:25:44 -0500 Subject: Remove --sync flag from `podman rm` Per discussion with Dan, it would be better to automatically handle potential runtime errors by automatically syncing if they occur. Retaining the flag for `ps` makes sense, as we won't even be calling the OCI runtime and as such won't see errors if the state desyncs, but rm can be handled automatically. The automatic desync handling code will take some additional work so we'll land this as-is (sync on ps is enough to solve most desync issues). Signed-off-by: Matthew Heon --- cmd/podman/rm.go | 10 ---------- completions/bash/podman | 1 - docs/podman-rm.1.md | 7 ------- 3 files changed, 18 deletions(-) (limited to 'cmd/podman') diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go index 224df4543..7c0569b78 100644 --- a/cmd/podman/rm.go +++ b/cmd/podman/rm.go @@ -20,10 +20,6 @@ var ( Usage: "Force removal of a running container. The default is false", }, LatestFlag, - cli.BoolFlag{ - Name: "sync", - Usage: "Sync container state with OCI runtime before removing", - }, cli.BoolFlag{ Name: "volumes, v", Usage: "Remove the volumes associated with the container (Not implemented yet)", @@ -77,12 +73,6 @@ func rmCmd(c *cli.Context) error { for _, container := range delContainers { con := container f := func() error { - if c.Bool("sync") { - if err := con.Sync(); err != nil { - return err - } - } - return runtime.RemoveContainer(ctx, con, c.Bool("force")) } diff --git a/completions/bash/podman b/completions/bash/podman index 1c21ab3d9..80ea53a74 100644 --- a/completions/bash/podman +++ b/completions/bash/podman @@ -1828,7 +1828,6 @@ _podman_rm() { -h --latest -l - --sync --volumes -v " diff --git a/docs/podman-rm.1.md b/docs/podman-rm.1.md index 57274c523..56664a8c1 100644 --- a/docs/podman-rm.1.md +++ b/docs/podman-rm.1.md @@ -24,13 +24,6 @@ Remove all containers. Can be used in conjunction with -f as well. Instead of providing the container name or ID, use the last created container. If you use methods other than Podman to run containers such as CRI-O, the last started container could be from either of those methods. -**--sync** - -Force a sync of container state with the OCI runtime before attempting to remove the container. -In some cases, a container's state in the runtime can become out of sync with Podman's state, -which can cause Podman to refuse to remove containers because it believes they are still running. -A sync will resolve this issue. - **--volumes, -v** Remove the volumes associated with the container. (Not yet implemented) -- cgit v1.2.3-54-g00ecf