Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pull error response docker rest api compatibility #20239

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions pkg/api/handlers/utils/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/containers/image/v5/types"
"github.com/containers/podman/v4/libpod"
api "github.com/containers/podman/v4/pkg/api/types"
"github.com/containers/podman/v4/pkg/errorhandling"
"github.com/containers/podman/v4/pkg/util"
"github.com/containers/storage"
"github.com/docker/distribution/registry/api/errcode"
Expand Down Expand Up @@ -141,6 +142,7 @@ func CompatPull(ctx context.Context, w http.ResponseWriter, runtime *libpod.Runt
statusWritten = true
}
}
progressSent := false

loop: // break out of for/select infinite loop
for {
Expand All @@ -149,6 +151,7 @@ loop: // break out of for/select infinite loop
select {
case e := <-progress:
writeStatusCode(http.StatusOK)
progressSent = true
switch e.Event {
case types.ProgressEventNewArtifact:
report.Status = "Pulling fs layer"
Expand Down Expand Up @@ -196,8 +199,21 @@ loop: // break out of for/select infinite loop
writeStatusCode(http.StatusInternalServerError)
}
}
if err := enc.Encode(report); err != nil {
logrus.Warnf("Failed to json encode error %q", err.Error())

// We need to check if no progress was sent previously. In that case, we should only return the base error message.
// This is necessary for compatibility with the Docker API.
if err != nil && !progressSent {
msg := errorhandling.Cause(err).Error()
message := jsonmessage.JSONError{
Message: msg,
}
if err := enc.Encode(message); err != nil {
logrus.Warnf("Failed to json encode error %q", err.Error())
}
} else {
if err := enc.Encode(report); err != nil {
logrus.Warnf("Failed to json encode error %q", err.Error())
}
}
flush()
break loop // break out of for/select infinite loop
Expand Down
4 changes: 4 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do
.[0].Comment=
done

# compat api pull image unauthorized message error
t POST "/images/create?fromImage=quay.io/idonotexist/idonotexist:dummy" 401 \
.message="unauthorized: access to the requested resource is not authorized"

# Export an image on the local
t GET libpod/images/nonesuch/get 404
t GET libpod/images/$iid/get?format=foo 500
Expand Down