-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
specifying --force,podman exit with 0 #14782
Conversation
@aonoa: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Signed-off-by: wufan <[email protected]>
First you have to sign your commits git commit -a --amend -s |
You need to add tests for this on each one of the --rm types. |
cmd/podman/networks/rm.go
Outdated
@@ -71,6 +71,9 @@ func networkRm(cmd *cobra.Command, args []string) error { | |||
fmt.Println(r.Name) | |||
} else { | |||
setExitCode(r.Err) | |||
if networkRmOptions.Force && registry.GetExitCode() == 1 { |
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 should only happen if the error is network does not exist, and this is the only error returned.
cmd/podman/pods/rm.go
Outdated
@@ -94,6 +94,9 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b | |||
responses, err := registry.ContainerEngine().PodRm(context.Background(), namesOrIDs, rmOptions) | |||
if err != nil { | |||
setExitCode(err) | |||
if rmOptions.Force && registry.GetExitCode() == 1 { | |||
registry.SetExitCode(define.ExecErrorCodeIgnore) |
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 should only happen if the error is pod does not exist, and this is the only error returned.
cmd/podman/volumes/rm.go
Outdated
@@ -73,6 +73,9 @@ func rm(cmd *cobra.Command, args []string) error { | |||
fmt.Println(r.Id) | |||
} else { | |||
setExitCode(r.Err) | |||
if rmOptions.Force && registry.GetExitCode() == 1 { |
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 should only happen if the error is volume does not exist, and this is the only error returned.
@@ -82,6 +82,9 @@ func rm(cmd *cobra.Command, args []string) error { | |||
} | |||
} | |||
registry.SetExitCode(report.ExitCode) | |||
if imageOpts.Force && registry.GetExitCode() == 1 { |
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 should only happen if the error is image does not exist, and this is the only error returned.
cmd/podman/containers/rm.go
Outdated
@@ -140,6 +140,9 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit | |||
} | |||
if setExit { | |||
setExitCode(r.Err) | |||
if rmOptions.Force && registry.GetExitCode() == 1 { |
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 should only happen if the error is container does not exist, and this is the only error returned.
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 recommend moving this into setExitCode() this will make the code much cleaner, same for the other places.
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 problem with that is the NOEXIST errors are all different.
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.
How are they all different? The setExitCode() already take care of setting this, so all what needs to be done is check if --force is set
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 am saying the current code is incorrect since errors other then NOTEXIST should be reported --force rm should only not fail if the Object does not exist.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aonoa, rhatdan 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 |
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.
Please use your real name in the commit sign off, see https://github.com/containers/podman/blob/main/CONTRIBUTING.md#sign-your-prs
This change also requires a release note in the PR description, please do not set it to none. This is a user facing change.
And also add some tests to make sure we do not regress in the future.
if registry.GetExitCode() == define.ExecErrorCodeIgnore { | ||
registry.SetExitCode(0) | ||
} |
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.
Do not use a special code for this, this will fail when a container exits with 128. Just set the exit code to 0 when you change 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.
Yes, I also think definition 128 is not good, but any error will make the return value not 0
Line 100 in 3426d56
if err := rootCmd.ExecuteContext(registry.GetContextWithOptions()); 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.
you could make the setExitCode function return the error and then set it to nil if it should not error
Or maybe more easy make --force imply --ignore, that should work al tleast for the commands who have --ignore.
cmd/podman/containers/rm.go
Outdated
@@ -140,6 +140,9 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit | |||
} | |||
if setExit { | |||
setExitCode(r.Err) | |||
if rmOptions.Force && registry.GetExitCode() == 1 { |
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 recommend moving this into setExitCode() this will make the code much cleaner, same for the other places.
My user name is not my real name |
I'll pass the DCO check manually, it's oversensitive about this. |
You have a lint error |
@aonoa can you fix the lint error?
|
I will add a blank line after the 4 line |
Signed-off-by: aonoa <[email protected]>
@aonoa CI isn't yet happy. |
Signed-off-by: aonoa <[email protected]>
Signed-off-by: aonoa <[email protected]>
Something wrong must have happened while rebasing. Can you rebase another time and squash the commits into one? |
@aonoa Can you rebase and clean this up? |
I opened up a replacement for this PR. #14959 Should I close this PR? |
Should, I don't know how to rebase, it's a mess now. |
Fixes: #14612
Signed-off-by: wufan [email protected]
Does this PR introduce a user-facing change?
The resource disappears at the end of the rm command, with --force podman exit with 0