Skip to content

Commit

Permalink
compat: Translate noprune into ImageRemoveOptions.NoPrune
Browse files Browse the repository at this point in the history
PR containers#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 <[email protected]>
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
ankon authored and vrothberg committed Apr 20, 2023
1 parent 911be1c commit b65ab52
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
8 changes: 2 additions & 6 deletions pkg/api/handlers/compat/images_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/server/register_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b65ab52

Please sign in to comment.