-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Fix error handling of incorrect --platform values #39527
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
Conversation
2afc2bf to
0b7db1f
Compare
0b7db1f to
7f5bd0d
Compare
cpuguy83
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
7f5bd0d to
7e54862
Compare
Codecov Report
@@ Coverage Diff @@
## master #39527 +/- ##
=========================================
Coverage ? 37.29%
=========================================
Files ? 609
Lines ? 45253
Branches ? 0
=========================================
Hits ? 16879
Misses ? 26083
Partials ? 2291 |
In situations where the containerd error is consumed directly and not received over gRPC, errors were not translated. This patch converts containerd errors to the correct HTTP status code. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Before we handled containerd errors, using an invalid platform produced a 500 status:
```bash
curl -v \
-X POST \
--unix-socket /var/run/docker.sock \
"http://localhost:2375/v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest" \
-H "Content-Type: application/json"
```
```
* Connected to localhost (docker.sock) port 80 (#0)
> POST /v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest HTTP/1.1
> Host: localhost:2375
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 500 Internal Server Error
< Api-Version: 1.40
< Content-Length: 85
< Content-Type: application/json
< Date: Mon, 15 Jul 2019 15:25:44 GMT
< Docker-Experimental: true
< Ostype: linux
< Server: Docker/19.03.0-rc2 (linux)
<
{"message":"\"foobar\": unknown operating system or architecture: invalid argument"}
```
That problem is now fixed, and the API correctly returns a 4xx status:
```bash
curl -v \
-X POST \
--unix-socket /var/run/docker.sock \
"http://localhost:2375/v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest" \
-H "Content-Type: application/json"
```
```
* Connected to localhost (/var/run/docker.sock) port 80 (#0)
> POST /v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest HTTP/1.1
> Host: localhost:2375
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 400 Bad Request
< Api-Version: 1.41
< Content-Type: application/json
< Docker-Experimental: true
< Ostype: linux
< Server: Docker/dev (linux)
< Date: Mon, 15 Jul 2019 15:13:42 GMT
< Content-Length: 85
<
{"message":"\"foobar\": unknown operating system or architecture: invalid argument"}
* Curl_http_done: called premature == 0
```
This patch adds tests to validate the behaviour
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
7e54862 to
9d1b4f5
Compare
dmcgowan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
|
||
| // statusCodeFromContainerdError returns status code for containerd errors when | ||
| // consumed directly (not through gRPC) | ||
| func statusCodeFromContainerdError(err error) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With containerd errors they only need to be unwrapped once with errors.Cause then a normal switch could be used. This is fine though for now, hopefully we can make the techniques more consistent so they can all be checked together in the future (for example maybe docker's version of the Is* functions can just also check containerd errors there too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should look at integrating them (if they all can be mapped). As to unwrapping; it's possible (although not the case currently) that errors are wrapped multiple times, so I guess recursively unwrapping is still ok to do
Relates to docker/docker-py#2382 (comment)
errdefs: convert containerd errors to the correct status code
In situations where the containerd error is consumed directly
and not received over gRPC, errors were not translated.
Add regression tests for invalid platform status codes
Before we handled containerd errors, using an invalid platform produced a 500 status:
That problem is now fixed, and the API correctly returns a 4xx status:
This patch adds tests to validate the behaviour
- How to verify it
- Description for the changelog