-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add status messages to podman --remote commit #20377
Conversation
Cockpit tests failed for commit 019ef12e449182bf735e8db61a21c38e33b6d515. @martinpitt, @jelly, @mvollmer please check. |
The cockpit-podman failure is right, this breaks commit error messages in the API. Create a container (immediately stops), enable the API, and commit the container:
With current podman it fails properly, with a 500 status code:
And the journal logs the failure:
With this PR, the call claims success (but of course does not actually create an image):
i.e. no real error code; and the journal logs a success, too:
|
pkg/api/handlers/libpod/images.go
Outdated
if err == nil { | ||
success = true | ||
} else { | ||
stdout.Write([]byte(err.Error() + "\n")) |
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.
This seems to be the problem: merely printing the error is not the same as actually posting it through utils.Error
as in line 524 -- I don't know how Go works, but I suspect that this err
is only scoped inside this go func, and doesn't exist any more outside, so this construction short-circuits the error handling below.
cc9f27c
to
b813806
Compare
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.
Some comments on the error handling. We should also add a test for an error scenario and make sure that the local and remote clients return the same error.
pkg/api/handlers/libpod/images.go
Outdated
go func() { | ||
defer cancel() | ||
commitImage, err = ctr.Commit(r.Context(), destImage, options) | ||
if err == nil { |
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.
I think we should preserve the error. The error can be returned in case we didn´t stream yet. The pull endpoints do that.
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.
Could write it to an error channel and use that in the switch table below.
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.
I do not know how to trigger a failure on this. If a user specifies a bad container name, this is caught before the commit line. It would be a very strange occurance like OOM or OODisk space to cause this to fail. Unless you have an idea.
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.
I'd try specifying some bogus change values:
podman (main) $ ./bin/podman commit --change BOGUS=FOO 123
Error: invalid change "BOGUS=FOO" - invalid instruction BOGUS
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.
Using this branch, I get the following output with podman-remote:
podman (commit) $ ./bin/podman-remote commit --change BOGUS=FOO 123
Error:
With 4.7, I get:
podman (commit) $ /usr/bin/podman-remote commit --change BOGUS=FOO 123
Error: CommitFailure: invalid change "BOGUS=FOO" - invalid instruction BOGU
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.
Fixed
pkg/api/server/register_images.go
Outdated
// description: format of the image manifest and metadata (default "oci") | ||
// description: the repository name for the created image | ||
// - in: query | ||
// name: Stream |
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.
// name: Stream | |
// name: stream |
pkg/api/handlers/libpod/images.go
Outdated
Stream string `json:"stream,omitempty"` | ||
Error *jsonmessage.JSONError `json:"errorDetail,omitempty"` | ||
// NOTE: `error` is being deprecated check https://github.com/moby/moby/blob/master/pkg/jsonmessage/jsonmessage.go#L148 | ||
ErrorMessage string `json:"error,omitempty"` // deprecate this slowly |
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.
Looks like a copy-paste issue: Why add this as a new field when the plan is to deprecate it?
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.
Cut and paste from Build
Fixed.
pkg/api/handlers/libpod/images.go
Outdated
} | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Set("Content-Type", "application/json") | ||
flush() |
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.
This happens too early. At that point, we may already have an error from Commit()
, so we should only send OK and the content-type on first successful stream.
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.
Moved to right after commit message above.
pkg/api/handlers/libpod/images.go
Outdated
// Channels all mux'ed in select{} below to follow API commit protocol | ||
stdout := channel.NewWriter(make(chan []byte)) | ||
defer stdout.Close() | ||
stderr := channel.NewWriter(make(chan []byte)) |
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.
IMO this should just be a chan error
so we could - in theory - do error checks later on.
pkg/api/handlers/libpod/images.go
Outdated
// Channels all mux'ed in select{} below to follow API commit protocol | ||
options.CommitOptions.ReportWriter = stdout | ||
var commitImage *libimage.Image | ||
success := false |
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.
I don't think we need this anymore. The order in the switch table will hit the error before streaming.
pkg/api/handlers/libpod/images.go
Outdated
logrus.Errorf("%v", err) | ||
} | ||
flush() | ||
case e := <-stderr.Chan(): |
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.
This is not being tested at the moment. I desire a test where the commit fails. Then we can make sure that the error reporting works correctly.
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.
Error handling isn't working yet. Let's please add a new test to check for errors.
pkg/api/handlers/libpod/images.go
Outdated
// Channels all mux'ed in select{} below to follow API commit protocol | ||
options.CommitOptions.ReportWriter = stdout | ||
var commitImage *libimage.Image | ||
failed := false |
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.
We don't need that variable. The error channel signals when there was an error and it will be checked before the stream case in the switch table.
pkg/api/handlers/libpod/images.go
Outdated
flush() | ||
case err := <-errorChan: | ||
writeStatusCode(http.StatusInternalServerError) | ||
m.Stream = err.Error() |
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.
m.Stream = err.Error() | |
m.ErrorMessage = err.Error() |
pkg/bindings/containers/commit.go
Outdated
body := response.Body.(io.Reader) | ||
dec := json.NewDecoder(body) | ||
for { | ||
var s struct { |
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.
The structs and JSON identifiers still differ. Let's move it into a place that both can share.
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.
@rhatdan that's still open.
Cockpit tests failed for commit 7b301309b7f425c1cf8e036c843d359c92b41793. @martinpitt, @jelly, @mvollmer please check. |
So that cockpit test failure is interesting, I think we need to discuss this a bit. This happens in a test which tries to commit a container with name "TEST". This is invalid, and is expected to report an error "repository name must be lowercase" through the API. The test functionally passes, but it stumbles over an additional logging of the API error on the browser console. I will adjust cockpit-podman's tests to ignore this browser error, which will unblock this PR. However, there's one weirdness: The full error message is now:
which is a bit smelly? Why not just the first half? That "Internal Server Error" is misleading. Is that intended? |
To clarify: The current test expects the error message with this pattern:
This PR drops the |
Drop the "CommitFailure:" part from the expected browser error when trying to commit a container with an invalid name. This is unnecessarily strict, and containers/podman#20377 is going to change it.
pkg/api/handlers/utils/images.go
Outdated
type BuildResponse struct { | ||
Stream string `json:"stream,omitempty"` | ||
Error *jsonmessage.JSONError `json:"errorDetail,omitempty"` | ||
// NOTE: `error` is being deprecated check https://github.com/moby/moby/blob/master/pkg/jsonmessage/jsonmessage.go#L148 |
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.
Same comment as above: Why use/introduce a new struct with already deprecated fields?
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.
@rhatdan that's still open.
Drop the "CommitFailure:" part from the expected browser error when trying to commit a container with an invalid name. This is unnecessarily strict, and containers/podman#20377 is going to change it.
d7343b1
to
53d92f1
Compare
Ephemeral COPR build failed. @containers/packit-build please check. |
f5da8a1
to
f799a01
Compare
@vrothberg @martinpitt PTANL |
LGTM, though there are a few open comments still |
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.
Added new comments on the few remaining open ones.
pkg/api/handlers/utils/images.go
Outdated
type BuildResponse struct { | ||
Stream string `json:"stream,omitempty"` | ||
Error *jsonmessage.JSONError `json:"errorDetail,omitempty"` | ||
// NOTE: `error` is being deprecated check https://github.com/moby/moby/blob/master/pkg/jsonmessage/jsonmessage.go#L148 |
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.
@rhatdan that's still open.
pkg/bindings/containers/commit.go
Outdated
body := response.Body.(io.Reader) | ||
dec := json.NewDecoder(body) | ||
for { | ||
var s struct { |
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.
@rhatdan that's still open.
pkg/bindings/images/build.go
Outdated
Stream string `json:"stream,omitempty"` | ||
Error string `json:"error,omitempty"` | ||
Stream string `json:"stream,omitempty"` | ||
Error *jsonmessage.JSONError `json:"errorDetail,omitempty"` | ||
} |
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.
This could re-use the new struct, could it?
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.
The deprecated warning is still being used in the docker compat bindings, so I can't remove.
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.
Can we use another/new struct? I would have hard time trying to understand the reasoning in the future. A new struct wouldn't raise the question of why only parts are used and what's deprecated etc.
Fixes: containers#19947 Signed-off-by: Daniel J Walsh <[email protected]>
LGTM |
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
Let's get it in. I bikesheded enough. Thanks, @rhatdan !
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhatdan, vrothberg The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Expect(session).Should(Exit(0)) | ||
Expect(session.ErrorToString()).To(BeEmpty()) |
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.
Shortcut (for future reference): To(ExitCleanly()). My bad for not catching this in time.
Fixes: #19947
Does this PR introduce a user-facing change?