diff options
author | Sujil02 <sushah@redhat.com> | 2020-04-02 22:56:59 -0400 |
---|---|---|
committer | Sujil02 <sushah@redhat.com> | 2020-04-17 17:30:58 -0400 |
commit | 37f3b191d5318b7d25893eabf4e57b568c326773 (patch) | |
tree | 8c2792aa1e7b4846dffc5708cf13a0eb500f4a19 /pkg/bindings | |
parent | aa97cb5f42a35de02d520f6c3006600505a3d6d9 (diff) | |
download | podman-37f3b191d5318b7d25893eabf4e57b568c326773.tar.gz podman-37f3b191d5318b7d25893eabf4e57b568c326773.tar.bz2 podman-37f3b191d5318b7d25893eabf4e57b568c326773.zip |
Add pod prune for api v2.
Add the ability to prune pods for api v2,
Includes the addition of force flag, for client side prompt.
Update test suite to support this use case.
Signed-off-by: Sujil02 <sushah@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r-- | pkg/bindings/pods/pods.go | 12 | ||||
-rw-r--r-- | pkg/bindings/test/pods_test.go | 14 |
2 files changed, 17 insertions, 9 deletions
diff --git a/pkg/bindings/pods/pods.go b/pkg/bindings/pods/pods.go index 83847614a..3c60fa2a0 100644 --- a/pkg/bindings/pods/pods.go +++ b/pkg/bindings/pods/pods.go @@ -98,17 +98,19 @@ func Pause(ctx context.Context, nameOrID string) (*entities.PodPauseReport, erro return &report, response.Process(&report) } -// Prune removes all non-running pods in local storage. -func Prune(ctx context.Context) error { +// Prune by default removes all non-running pods in local storage. +// And with force set true removes all pods. +func Prune(ctx context.Context) ([]*entities.PodPruneReport, error) { + var reports []*entities.PodPruneReport conn, err := bindings.GetClient(ctx) if err != nil { - return err + return nil, err } response, err := conn.DoRequest(nil, http.MethodPost, "/pods/prune", nil) if err != nil { - return err + return nil, err } - return response.Process(nil) + return reports, response.Process(&reports) } // List returns all pods in local storage. The optional filters parameter can diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go index 579161b26..4d682a522 100644 --- a/pkg/bindings/test/pods_test.go +++ b/pkg/bindings/test/pods_test.go @@ -262,7 +262,7 @@ var _ = Describe("Podman pods", func() { var newpod2 string = "newpod2" bt.Podcreate(&newpod2) // No pods pruned since no pod in exited state - err = pods.Prune(bt.conn) + pruneResponse, err := pods.Prune(bt.conn) Expect(err).To(BeNil()) podSummary, err := pods.List(bt.conn, nil) Expect(err).To(BeNil()) @@ -279,13 +279,19 @@ var _ = Describe("Podman pods", func() { Expect(err).To(BeNil()) // FIXME sujil please fix this //Expect(response.State.Status).To(Equal(define.PodStateExited)) - err = pods.Prune(bt.conn) + pruneResponse, err = pods.Prune(bt.conn) Expect(err).To(BeNil()) + // Validate status and record pod id of pod to be pruned + //Expect(response.State.Status).To(Equal(define.PodStateExited)) + //podID := response.Config.ID + // Check if right pod was pruned + Expect(len(pruneResponse)).To(Equal(1)) + // One pod is pruned hence only one pod should be active. podSummary, err = pods.List(bt.conn, nil) Expect(err).To(BeNil()) Expect(len(podSummary)).To(Equal(1)) - // Test prune all pods in exited state. + // Test prune multiple pods. bt.Podcreate(&newpod) _, err = pods.Start(bt.conn, newpod) Expect(err).To(BeNil()) @@ -311,7 +317,7 @@ var _ = Describe("Podman pods", func() { Expect(define.StringToContainerStatus(i.State)). To(Equal(define.ContainerStateStopped)) } - err = pods.Prune(bt.conn) + _, err = pods.Prune(bt.conn) Expect(err).To(BeNil()) podSummary, err = pods.List(bt.conn, nil) Expect(err).To(BeNil()) |