compat: Translate `noprune` into ImageRemoveOptions.NoPrune

PR #15093 implemented support for NoPrune in the ImageRemoveOptions,
this PR simply brings that also to the compat API along with
regression tests.

Signed-off-by: Andreas Kohn <andreas.kohn@gmail.com>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Andreas Kohn 2023-03-31 18:18:32 +02:00 committed by Valentin Rothberg
parent 911be1cbcb
commit b65ab52d8d
3 changed files with 33 additions and 7 deletions

View File

@ -29,11 +29,6 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) {
utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err))
return
}
if _, found := r.URL.Query()["noprune"]; found {
if query.NoPrune {
utils.UnSupportedParameter("noprune")
}
}
name := utils.GetName(r)
possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, name)
if err != nil {
@ -44,7 +39,8 @@ func RemoveImage(w http.ResponseWriter, r *http.Request) {
imageEngine := abi.ImageEngine{Libpod: runtime}
options := entities.ImageRemoveOptions{
Force: query.Force,
Force: query.Force,
NoPrune: query.NoPrune,
}
report, rmerrors := imageEngine.Remove(r.Context(), []string{possiblyNormalizedName}, options)
if len(rmerrors) > 0 && rmerrors[0] != nil {

View File

@ -229,7 +229,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// - in: query
// name: noprune
// type: boolean
// description: not supported. will be logged as an invalid parameter if enabled
// description: do not remove dangling parent images
// produces:
// - application/json
// responses:

View File

@ -266,4 +266,34 @@ t GET "libpod/events?stream=false&since=$START" 200 \
t GET "events?stream=false&since=$START" 200 \
'select(.status | contains("delete")).Action=delete'
# Test image removal with `noprune={true,false}`
podman create --name c_test1 $IMAGE true
podman commit -q c_test1 i_test1
podman create --name c_test2 i_test1 true
podman commit -q c_test2 i_test2
podman create --name c_test3 i_test2 true
podman commit -q c_test3 i_test3
t GET libpod/images/i_test1/json 200
iid_test1=$(jq -r '.Id' <<<"$output")
t GET libpod/images/i_test2/json 200
iid_test2=$(jq -r '.Id' <<<"$output")
t GET libpod/images/i_test3/json 200
iid_test3=$(jq -r '.Id' <<<"$output")
podman untag $iid_test1
podman untag $iid_test2
podman rm -af
# Deleting i_test3 with --no-prune must not remove _2 and _1.
t DELETE images/$iid_test3?noprune=true 200
t GET libpod/images/i_test3/exists 404
t GET libpod/images/$iid_test1/exists 204
t GET libpod/images/$iid_test2/exists 204
t DELETE images/$iid_test2?noprune=false 200
t GET libpod/images/$iid_test1/exists 404
t GET libpod/images/$iid_test2/exists 404
# vim: filetype=sh