diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2021-01-18 14:49:53 -0500 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2021-01-20 07:37:13 -0500 |
commit | e7df73efadd36e2489954ee9a766a3fbfe4eafeb (patch) | |
tree | 4d27e452a26e4b6d6f942c80da75940ee57d5582 /pkg/bindings | |
parent | 7d024a2fc8c675e4d34e3b34b56b6217a48ef9ce (diff) | |
download | podman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.tar.gz podman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.tar.bz2 podman-e7df73efadd36e2489954ee9a766a3fbfe4eafeb.zip |
Fix handling of container remove
I found several problems with container remove
podman-remote rm --all
Was not handled
podman-remote rm --ignore
Was not handled
Return better errors when attempting to remove an --external container.
Currently we return the container does not exists, as opposed to container
is an external container that is being used.
This patch also consolidates the tunnel code to use the same code for
removing the container, as the local API, removing duplication of code
and potential problems.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r-- | pkg/bindings/containers/containers.go | 12 | ||||
-rw-r--r-- | pkg/bindings/containers/types.go | 2 | ||||
-rw-r--r-- | pkg/bindings/containers/types_remove_options.go | 32 |
3 files changed, 44 insertions, 2 deletions
diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go index 73e4d1d3d..40fcfbded 100644 --- a/pkg/bindings/containers/containers.go +++ b/pkg/bindings/containers/containers.go @@ -71,8 +71,10 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*reports.PruneReport, } // Remove removes a container from local storage. The force bool designates -// that the container should be removed forcibly (example, even it is running). The volumes -// bool dictates that a container's volumes should also be removed. +// that the container should be removed forcibly (example, even it is running). +// The volumes bool dictates that a container's volumes should also be removed. +// The All option indicates that all containers should be removed +// The Ignore option indicates that if a container did not exist, ignore the error func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) error { if options == nil { options = new(RemoveOptions) @@ -85,9 +87,15 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) error if v := options.GetVolumes(); options.Changed("Volumes") { params.Set("v", strconv.FormatBool(v)) } + if all := options.GetAll(); options.Changed("All") { + params.Set("all", strconv.FormatBool(all)) + } if force := options.GetForce(); options.Changed("Force") { params.Set("force", strconv.FormatBool(force)) } + if ignore := options.GetIgnore(); options.Changed("Ignore") { + params.Set("ignore", strconv.FormatBool(ignore)) + } response, err := conn.DoRequest(nil, http.MethodDelete, "/containers/%s", params, nil, nameOrID) if err != nil { return err diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go index 43cb58a54..24604fa83 100644 --- a/pkg/bindings/containers/types.go +++ b/pkg/bindings/containers/types.go @@ -122,6 +122,8 @@ type PruneOptions struct { //go:generate go run ../generator/generator.go RemoveOptions // RemoveOptions are optional options for removing containers type RemoveOptions struct { + All *bool + Ignore *bool Force *bool Volumes *bool } diff --git a/pkg/bindings/containers/types_remove_options.go b/pkg/bindings/containers/types_remove_options.go index e21fb41f7..3ef32fa03 100644 --- a/pkg/bindings/containers/types_remove_options.go +++ b/pkg/bindings/containers/types_remove_options.go @@ -87,6 +87,38 @@ func (o *RemoveOptions) ToParams() (url.Values, error) { return params, nil } +// WithAll +func (o *RemoveOptions) WithAll(value bool) *RemoveOptions { + v := &value + o.All = v + return o +} + +// GetAll +func (o *RemoveOptions) GetAll() bool { + var all bool + if o.All == nil { + return all + } + return *o.All +} + +// WithIgnore +func (o *RemoveOptions) WithIgnore(value bool) *RemoveOptions { + v := &value + o.Ignore = v + return o +} + +// GetIgnore +func (o *RemoveOptions) GetIgnore() bool { + var ignore bool + if o.Ignore == nil { + return ignore + } + return *o.Ignore +} + // WithForce func (o *RemoveOptions) WithForce(value bool) *RemoveOptions { v := &value |