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

exec cannot read stdout/stderr data after stdin reaches EOF #1689

Open
esw-amzn opened this issue Feb 6, 2025 · 2 comments
Open

exec cannot read stdout/stderr data after stdin reaches EOF #1689

esw-amzn opened this issue Feb 6, 2025 · 2 comments
Labels
bug Something isn't working client kube Client related

Comments

@esw-amzn
Copy link

esw-amzn commented Feb 6, 2025

Current and expected behavior

I'm trying to implement a tool for my application that has similar behavior to kubectl exec. I've encountered an issue when piping data to stdin. As soon as stdin is closed the Rust client closes both stdin and stdout streams and there is no way to get any remaining stdout data.

The equivalent kubectl command would be something like this.

$ echo hello world | kubectl -n my_namespace exec --stdin my_pod -- cat -
hello world

In this case "hello world" is properly echoed back. When I try the equivalent of this with my Rust tool using kube-client I never get the echoed response.

Possible solution

It appears the issue is with the break here. https://github.com/kube-rs/kube/blob/main/kube-client/src/api/remote_command.rs#L342

This break causes the entire message loop to shut down as soon as the end of stdin is reached. So it is not possible to get any remaining stdout/stderr data back after stdin is finished. It seems removing the break would fix the issue.

Looking at the Go client implementation, it appears that the Go implementation continues to read from stdout/stderr even after stdin is closed. https://github.com/kubernetes/client-go/blob/master/tools/remotecommand/v2.go#L183-L188

Additional context

No response

Environment

$ kubectl version
Client Version: v1.31.1
Kustomize Version: v5.4.2
Server Version: v1.30.8-eks-2d5f260

Configuration and features

k8s-openapi = { version = "0.24", features = ["v1_30", "schemars"] }
kube = { version = "0.98", features = ["runtime", "ws", "admission", "derive"] }

Affected crates

kube-client

Would you like to work on fixing this bug?

maybe

@esw-amzn esw-amzn added the bug Something isn't working label Feb 6, 2025
@clux
Copy link
Member

clux commented Feb 7, 2025

Hey there. Thanks for this!

I think this makes sense to do. Would you like to submit a PR?
..it might be worth checking that it doesn't cause any other problems with the pod_ examples. They don't all run on CI, and we don't test that loop that deeply.

@clux clux added the client kube Client related label Feb 7, 2025
@esw-amzn
Copy link
Author

esw-amzn commented Feb 7, 2025

I'll try an make a PR for this. It looks like the fix is more involved than just removing the break.

esw-amzn added a commit to esw-amzn/kube that referenced this issue Feb 11, 2025
esw-amzn added a commit to esw-amzn/kube that referenced this issue Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working client kube Client related
Projects
None yet
Development

No branches or pull requests

2 participants