summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-12-23 06:41:55 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-01-11 14:33:54 -0500
commit8f2358eeaa59fe369eebc6186403f95c2d66e49b (patch)
treea454ef259ab28f85b17f53b3273725480aa78515 /pkg/bindings
parentc4142ce0cfff792092bf420950b1985058cc241c (diff)
downloadpodman-8f2358eeaa59fe369eebc6186403f95c2d66e49b.tar.gz
podman-8f2358eeaa59fe369eebc6186403f95c2d66e49b.tar.bz2
podman-8f2358eeaa59fe369eebc6186403f95c2d66e49b.zip
Add podman rm --depend
This option causes Podman to not only remove the specified containers but all of the containers that depend on the specified containers. Fixes: https://github.com/containers/podman/issues/10360 Also ran codespell on the code Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/containers.go11
-rw-r--r--pkg/bindings/containers/types.go1
-rw-r--r--pkg/bindings/containers/types_remove_options.go15
-rw-r--r--pkg/bindings/test/containers_test.go47
4 files changed, 47 insertions, 27 deletions
diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go
index 14a173025..0148e62cb 100644
--- a/pkg/bindings/containers/containers.go
+++ b/pkg/bindings/containers/containers.go
@@ -78,25 +78,26 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*reports.PruneReport,
// 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 {
+func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*reports.RmReport, error) {
if options == nil {
options = new(RemoveOptions)
}
+ var reports []*reports.RmReport
conn, err := bindings.GetClient(ctx)
if err != nil {
- return err
+ return reports, err
}
params, err := options.ToParams()
if err != nil {
- return err
+ return reports, err
}
response, err := conn.DoRequest(ctx, nil, http.MethodDelete, "/containers/%s", params, nil, nameOrID)
if err != nil {
- return err
+ return reports, err
}
defer response.Body.Close()
- return response.Process(nil)
+ return reports, response.Process(&reports)
}
// Inspect returns low level information about a Container. The nameOrID can be a container name
diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go
index 81a53a549..db3eb3e1b 100644
--- a/pkg/bindings/containers/types.go
+++ b/pkg/bindings/containers/types.go
@@ -138,6 +138,7 @@ type PruneOptions struct {
//go:generate go run ../generator/generator.go RemoveOptions
// RemoveOptions are optional options for removing containers
type RemoveOptions struct {
+ Depend *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 1e52e819d..7fa198d2f 100644
--- a/pkg/bindings/containers/types_remove_options.go
+++ b/pkg/bindings/containers/types_remove_options.go
@@ -17,6 +17,21 @@ func (o *RemoveOptions) ToParams() (url.Values, error) {
return util.ToParams(o)
}
+// WithDepend set field Depend to given value
+func (o *RemoveOptions) WithDepend(value bool) *RemoveOptions {
+ o.Depend = &value
+ return o
+}
+
+// GetDepend returns value of field Depend
+func (o *RemoveOptions) GetDepend() bool {
+ if o.Depend == nil {
+ var z bool
+ return z
+ }
+ return *o.Depend
+}
+
// WithIgnore set field Ignore to given value
func (o *RemoveOptions) WithIgnore(value bool) *RemoveOptions {
o.Ignore = &value
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index b6c06756b..cab032a40 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -175,7 +175,7 @@ var _ = Describe("Podman containers ", func() {
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid, nil)
Expect(err).To(BeNil())
- err = containers.Remove(bt.conn, cid, nil)
+ _, err = containers.Remove(bt.conn, cid, nil)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -188,8 +188,10 @@ var _ = Describe("Podman containers ", func() {
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid, nil)
Expect(err).To(BeNil())
- err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true))
+ rmResponse, err := containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true))
Expect(err).To(BeNil())
+ Expect(len(reports.RmReportsErrs(rmResponse))).To(Equal(0))
+ Expect(len(reports.RmReportsIds(rmResponse))).To(Equal(1))
})
It("podman stop a paused container by name", func() {
@@ -669,7 +671,8 @@ var _ = Describe("Podman containers ", func() {
})
It("podman remove bogus container", func() {
- err = containers.Remove(bt.conn, "foobar", nil)
+ _, err := containers.Remove(bt.conn, "foobar", nil)
+ Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
})
@@ -679,7 +682,7 @@ var _ = Describe("Podman containers ", func() {
_, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
- err = containers.Remove(bt.conn, name, nil)
+ _, err = containers.Remove(bt.conn, name, nil)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -690,7 +693,7 @@ var _ = Describe("Podman containers ", func() {
cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
- err = containers.Remove(bt.conn, cid, nil)
+ _, err = containers.Remove(bt.conn, cid, nil)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -700,22 +703,22 @@ var _ = Describe("Podman containers ", func() {
var name = "top"
_, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
- // Removing running container should fail
- err = containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithForce(true))
+ // Removing running container should succeed
+ rmResponse, err := containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithForce(true))
Expect(err).To(BeNil())
- //code, _ := bindings.CheckResponseCode(err)
- //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ Expect(len(reports.RmReportsErrs(rmResponse))).To(Equal(0))
+ Expect(len(reports.RmReportsIds(rmResponse))).To(Equal(1))
})
It("podman forcibly remove running container by ID", func() {
var name = "top"
cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
- // Removing running container should fail
- err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true))
+ // Forcably Removing running container should succeed
+ rmResponse, err := containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true))
Expect(err).To(BeNil())
- //code, _ := bindings.CheckResponseCode(err)
- //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ Expect(len(reports.RmReportsErrs(rmResponse))).To(Equal(0))
+ Expect(len(reports.RmReportsIds(rmResponse))).To(Equal(1))
})
It("podman remove running container and volume by name", func() {
@@ -723,7 +726,7 @@ var _ = Describe("Podman containers ", func() {
_, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
- err = containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithVolumes(true))
+ _, err = containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithVolumes(true))
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -734,7 +737,7 @@ var _ = Describe("Podman containers ", func() {
cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
- err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithVolumes(true))
+ _, err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithVolumes(true))
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -744,11 +747,11 @@ var _ = Describe("Podman containers ", func() {
var name = "top"
_, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
- // Removing running container should fail
- err = containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithVolumes(true).WithForce(true))
+ // Forcibly Removing running container should succeed
+ rmResponse, err := containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithVolumes(true).WithForce(true))
Expect(err).To(BeNil())
- //code, _ := bindings.CheckResponseCode(err)
- //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ Expect(len(reports.RmReportsErrs(rmResponse))).To(Equal(0))
+ Expect(len(reports.RmReportsIds(rmResponse))).To(Equal(1))
})
It("podman forcibly remove running container and volume by ID", func() {
@@ -756,10 +759,10 @@ var _ = Describe("Podman containers ", func() {
cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
- err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true).WithVolumes(true))
+ rmResponse, err := containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true).WithVolumes(true))
Expect(err).To(BeNil())
- //code, _ := bindings.CheckResponseCode(err)
- //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ Expect(len(reports.RmReportsErrs(rmResponse))).To(Equal(0))
+ Expect(len(reports.RmReportsIds(rmResponse))).To(Equal(1))
})
It("List containers with filters", func() {