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

Do not print an error message on non-0 exec exit code #3462

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions pkg/cmd/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ func execActionWithContainer(ctx context.Context, client *containerd.Client, con
return nil
}
status := <-statusC
code, _, err := status.Result()
_, _, err = status.Result()
if err != nil {
return err
}
if code != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zouyee not displaying the message is one thing, but clearly we still need to error out.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The executable we ran inside the container that errored, we need to print error ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to return an error from this method, otherwise nerdctl will exit 0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does exec function care about the results of execution inside the container?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be just same as Docker

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nerdctl exec

nerdctl -n k8s.io exec  xxx bash -c  'bash ./faketime.sh xxx';echo $?
tomcat: stopped
tomcat: started
FATA[0005] exec failed with exit code 1
1

docker exec

docker exec xxx  bash -c  'bash ./faketime.sh xxx';echo $?
tomcat: stopped
tomcat: started
1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should do the same thing as docker.
With your patch right now, we no longer return exit 1 because you do not return a go error.

Copy link
Member

@fahedouch fahedouch Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zouyee you may write stderr to /dev/null as workaround

return fmt.Errorf("exec failed with exit code %d", code)
}
return nil
}

Expand Down
Loading