Merge pull request #2332 from baude/remotevolumeprune

volume prune
This commit is contained in:
OpenShift Merge Robot
2019-02-14 22:52:03 +01:00
committed by GitHub
14 changed files with 101 additions and 52 deletions

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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
}