You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have a background goroutine that cancels the context if I'm idle. Cancellation works fine, the network connection is closed, but the process on the pod is still running. I want to kill the process on the pod when the context is cancelled. I couldn't find a way for it, is it possible out of the box in k8s client?
If not, what would be the best way to achieve this? I'm thinking making signature of the process and killing it with another command when the context is cancelled. But I'm not sure if it's the best way to do it.
The text was updated successfully, but these errors were encountered:
@DumbMachine I recently encountered the same issue. I hope the maintainers of client-go can put in a more elegant fix, but I did find a workaround. Here's a quick general example. This example also assumes you're passing cancel() down to the goroutine you mentioned and calling it after the idle timeout.
ctx, cancel:=context.WithCancel(context.TODO())
stdinPipeReader, stdinPipeWriter:=io.Pipe()
gofunc() {
// copy the original stdin to the pipe// this will also continue to copy new input in an interactive shell sessionio.Copy(stdinPipeWriter, stdin)
}()
gofunc() {
// on context cancel, send ctrl-c to the process by writing to the pipe<-ctx.Done()
stdinPipeWriter.Write([]byte("\x03"))
// if you're using an interactive shell, you may need to send ctrl-c and exit// stdinPipeWriter.Write([]byte("\x03\nexit\n"))
}()
exec, err:=remotecommand.NewSPDYExecutor(config, method, url)
iferr!=nil {
returnerr
}
exec.StreamWithContext(ctx, remotecommand.StreamOptions{
// pass the pipe reader instead of the original stdinStdin: stdinPipeReader,
Stdout: stdout,
Stderr: stderr,
Tty: tty,
TerminalSizeQueue: terminalSizeQueue,
})
I'm executing some interactive commands on a pod with the following code:
Have a background goroutine that cancels the context if I'm idle. Cancellation works fine, the network connection is closed, but the process on the pod is still running. I want to kill the process on the pod when the context is cancelled. I couldn't find a way for it, is it possible out of the box in k8s client?
If not, what would be the best way to achieve this? I'm thinking making signature of the process and killing it with another command when the context is cancelled. But I'm not sure if it's the best way to do it.
The text was updated successfully, but these errors were encountered: