summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat/volumes.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2021-01-07 15:25:44 -0700
committerJhon Honce <jhonce@redhat.com>2021-01-07 15:32:32 -0700
commitb059e1044f5a1bac6a531e6241e24f82c8c6a9c0 (patch)
tree9e40297a48967cb64d2f3325f9ee15b3ea31aa7f /pkg/api/handlers/compat/volumes.go
parent78cda71372485f163909525f8d07194920968486 (diff)
downloadpodman-b059e1044f5a1bac6a531e6241e24f82c8c6a9c0.tar.gz
podman-b059e1044f5a1bac6a531e6241e24f82c8c6a9c0.tar.bz2
podman-b059e1044f5a1bac6a531e6241e24f82c8c6a9c0.zip
Restore compatible API for prune endpoints
* Restore correct API endpoint payloads including reclaimed space numbers * Include tests for API prune endpoints * Clean up function signatures with unused parameters * Update swagger for /networks/prune Fixes #8891 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/api/handlers/compat/volumes.go')
-rw-r--r--pkg/api/handlers/compat/volumes.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/pkg/api/handlers/compat/volumes.go b/pkg/api/handlers/compat/volumes.go
index 1188d8f84..4903bbad4 100644
--- a/pkg/api/handlers/compat/volumes.go
+++ b/pkg/api/handlers/compat/volumes.go
@@ -1,6 +1,7 @@
package compat
import (
+ "bytes"
"encoding/json"
"net/http"
"net/url"
@@ -8,6 +9,7 @@ import (
"github.com/containers/podman/v2/libpod"
"github.com/containers/podman/v2/libpod/define"
+ "github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/api/handlers/utils"
"github.com/containers/podman/v2/pkg/domain/filters"
"github.com/containers/podman/v2/pkg/domain/infra/abi/parse"
@@ -268,17 +270,29 @@ func PruneVolumes(w http.ResponseWriter, r *http.Request) {
utils.InternalServerError(w, err)
return
}
+
+ var errorMsg bytes.Buffer
+ var reclaimedSpace uint64
prunedIds := make([]string, 0, len(pruned))
for _, v := range pruned {
- // XXX: This drops any pruning per-volume error messages on the floor
+ if v.Err != nil {
+ errorMsg.WriteString(v.Err.Error())
+ errorMsg.WriteString("; ")
+ continue
+ }
prunedIds = append(prunedIds, v.Id)
+ reclaimedSpace += v.Size
}
- pruneResponse := docker_api_types.VolumesPruneReport{
- VolumesDeleted: prunedIds,
- // TODO: We don't have any insight into how much space was reclaimed
- // from `PruneVolumes()` but it's not nullable
- SpaceReclaimed: 0,
+ if errorMsg.Len() > 0 {
+ utils.InternalServerError(w, errors.New(errorMsg.String()))
+ return
}
- utils.WriteResponse(w, http.StatusOK, pruneResponse)
+ payload := handlers.VolumesPruneReport{
+ VolumesPruneReport: docker_api_types.VolumesPruneReport{
+ VolumesDeleted: prunedIds,
+ SpaceReclaimed: reclaimedSpace,
+ },
+ }
+ utils.WriteResponse(w, http.StatusOK, payload)
}