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

specifying --force,podman exit with 0 #14782

Closed
wants to merge 6 commits into from
Closed

Conversation

aonoa
Copy link
Contributor

@aonoa aonoa commented Jun 30, 2022

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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 30, 2022

@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.

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Jun 30, 2022
@rhatdan
Copy link
Member

rhatdan commented Jun 30, 2022

First you have to sign your commits

git commit -a --amend -s
git push --force

@rhatdan
Copy link
Member

rhatdan commented Jun 30, 2022

You need to add tests for this on each one of the --rm types.

@@ -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 {
Copy link
Member

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.

@@ -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)
Copy link
Member

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.

@@ -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 {
Copy link
Member

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 {
Copy link
Member

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.

@@ -140,6 +140,9 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
}
if setExit {
setExitCode(r.Err)
if rmOptions.Force && registry.GetExitCode() == 1 {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 30, 2022

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 30, 2022
Copy link
Member

@Luap99 Luap99 left a 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.

Comment on lines +109 to +111
if registry.GetExitCode() == define.ExecErrorCodeIgnore {
registry.SetExitCode(0)
}
Copy link
Member

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.

Copy link
Contributor Author

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

if err := rootCmd.ExecuteContext(registry.GetContextWithOptions()); err != nil {

Copy link
Member

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.

@@ -140,6 +140,9 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
}
if setExit {
setExitCode(r.Err)
if rmOptions.Force && registry.GetExitCode() == 1 {
Copy link
Member

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.

@aonoa
Copy link
Contributor Author

aonoa commented Jun 30, 2022

请在提交签名时使用您的真实姓名,请参阅https://github.com/containers/podman/blob/main/CONTRIBUTING.md#sign-your-prs

My user name is not my real name

@mheon
Copy link
Member

mheon commented Jun 30, 2022

I'll pass the DCO check manually, it's oversensitive about this.

@mheon
Copy link
Member

mheon commented Jun 30, 2022

You have a lint error

@vrothberg
Copy link
Member

vrothberg commented Jul 5, 2022

@aonoa can you fix the lint error?

Running golangci-lint for tunnel
Build Tags tunnel: apparmor,seccomp,selinux,linter,remote
Skipped directories tunnel: pkg/api,pkg/machine/e2e
cmd/podman/images/rm.go:4: File is not goimports-ed (goimports)
"fmt"

@aonoa
Copy link
Contributor Author

aonoa commented Jul 5, 2022

@aonoa你能修复 lint 错误吗?

为隧道运行 golangci-lint
构建标签隧道:apparmor,seccomp,selinux,linter,remote
跳过的目录隧道:pkg/api,pkg/machine/e2e
cmd/podman/images/rm.go:4:文件未goimports-ed( goimports)
"fmt"

I will add a blank line after the 4 line
golangci/golangci-lint#138 (comment)

@vrothberg
Copy link
Member

@aonoa CI isn't yet happy.

@vrothberg
Copy link
Member

Something wrong must have happened while rebasing. Can you rebase another time and squash the commits into one?

@rhatdan
Copy link
Member

rhatdan commented Jul 18, 2022

@aonoa Can you rebase and clean this up?

@rhatdan
Copy link
Member

rhatdan commented Jul 18, 2022

I opened up a replacement for this PR. #14959 Should I close this PR?

@aonoa
Copy link
Contributor Author

aonoa commented Jul 19, 2022

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.

@rhatdan rhatdan closed this Jul 19, 2022
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman image rm -f returns an status code of 1 when it should return 0
5 participants