aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-14 22:52:03 +0100
committerGitHub <noreply@github.com>2019-02-14 22:52:03 +0100
commitae8cc41295c4ff6f6f82372221c66c250691e4f6 (patch)
tree197c210011a5c40a9beccafea8a22c52314f28de /libpod
parent1a9128d1e4851df7c0316e0b861e70605fd262f6 (diff)
parent5be818e715d57f98e4a930632bc599e3fee3aaed (diff)
downloadpodman-ae8cc41295c4ff6f6f82372221c66c250691e4f6.tar.gz
podman-ae8cc41295c4ff6f6f82372221c66c250691e4f6.tar.bz2
podman-ae8cc41295c4ff6f6f82372221c66c250691e4f6.zip
Merge pull request #2332 from baude/remotevolumeprune
volume prune
Diffstat (limited to 'libpod')
-rw-r--r--libpod/adapter/runtime.go5
-rw-r--r--libpod/adapter/runtime_remote.go14
-rw-r--r--libpod/runtime_volume.go24
3 files changed, 43 insertions, 0 deletions
diff --git a/libpod/adapter/runtime.go b/libpod/adapter/runtime.go
index 3146cf5db..02ef9af07 100644
--- a/libpod/adapter/runtime.go
+++ b/libpod/adapter/runtime.go
@@ -305,3 +305,8 @@ func (r *LocalRuntime) Build(ctx context.Context, c *cliconfig.BuildValues, opti
return r.Runtime.Build(ctx, options, dockerfiles...)
}
+
+// PruneVolumes is a wrapper function for libpod PruneVolumes
+func (r *LocalRuntime) PruneVolumes(ctx context.Context) ([]string, []error) {
+ return r.Runtime.PruneVolumes(ctx)
+}
diff --git a/libpod/adapter/runtime_remote.go b/libpod/adapter/runtime_remote.go
index a96676ee2..d0a3c5b1f 100644
--- a/libpod/adapter/runtime_remote.go
+++ b/libpod/adapter/runtime_remote.go
@@ -642,3 +642,17 @@ func varlinkVolumeToVolume(r *LocalRuntime, volumes []iopodman.Volume) []*Volume
}
return vols
}
+
+// PruneVolumes removes all unused volumes from the remote system
+func (r *LocalRuntime) PruneVolumes(ctx context.Context) ([]string, []error) {
+ var errs []error
+ prunedNames, prunedErrors, err := iopodman.VolumesPrune().Call(r.Conn)
+ if err != nil {
+ return []string{}, []error{err}
+ }
+ // We need to transform the string results of the error into actual error types
+ for _, e := range prunedErrors {
+ errs = append(errs, errors.New(e))
+ }
+ return prunedNames, errs
+}
diff --git a/libpod/runtime_volume.go b/libpod/runtime_volume.go
index 485f64bf1..beae50ac9 100644
--- a/libpod/runtime_volume.go
+++ b/libpod/runtime_volume.go
@@ -154,3 +154,27 @@ func (r *Runtime) GetAllVolumes() ([]*Volume, error) {
return r.state.AllVolumes()
}
+
+// PruneVolumes removes unused volumes from the system
+func (r *Runtime) PruneVolumes(ctx context.Context) ([]string, []error) {
+ var (
+ prunedIDs []string
+ pruneErrors []error
+ )
+ vols, err := r.GetAllVolumes()
+ if err != nil {
+ pruneErrors = append(pruneErrors, err)
+ return nil, pruneErrors
+ }
+
+ for _, vol := range vols {
+ if err := r.RemoveVolume(ctx, vol, false, true); err != nil {
+ if err != ErrVolumeBeingUsed {
+ pruneErrors = append(pruneErrors, err)
+ }
+ continue
+ }
+ prunedIDs = append(prunedIDs, vol.Name())
+ }
+ return prunedIDs, pruneErrors
+}