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

Support terminal resizes #240

Merged
merged 2 commits into from
May 2, 2019
Merged

Conversation

lizardruss
Copy link
Contributor

@lizardruss lizardruss commented Apr 26, 2019

This adds resize support for exec and attach #239

There were also some false positives with the associated tests. I created a solution, but open to alternative approaches.

The name TerminalSizeQueue was taken from the kubernetes code base, and in this context it's a Readable stream that abstracts the sending of a TerminalSize interface over the resize stream.

I also added examples that resize the pod's terminal with process.stdout

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 26, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 26, 2019
@lizardruss
Copy link
Contributor Author

/assign @brendandburns

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const terminalSizeQueue = new k8s.TerminalSizeQueue();
Copy link
Contributor

Choose a reason for hiding this comment

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

@lizardruss Thanks for the contribution! I haven't had the chance to test it out yet.

Wondering if it is better to move this logic private to the client? So the library binds the events and adds to the internal queues.

It feels like its a standard event on NodeJS.WriteStream so maybe we can hide this implementation logic from the users of the client?

It not only would solve a bunch of copy paste between attach and exec but also means that it becomes improvement clients get without any code changes.

Unless this is how it is with most of the other clients @brendanburns your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion! I like the idea of removing the TerminalSizeQueue class. I mostly just ported it from the kubectl codebase, and it didn't feel quite right.

If I understand you correctly, you're suggesting to use the stdout argument to detect resizes. Currently its typed as Writable | null for exec and Writable | any for attach. Changing to NodeJS.WriteStream might be a breaking change.

Another potential issue is that NodeJS.WriteStream's rows and columns properties are optional. I think tty.WriteStream might be the more accurate type, since NodeJS.WriteStream doesn't have a documented resize event. I'll make that change in the examples.

For more context, I won't be using process.stdout for my use case. Instead I'll be using this from a set of web based services that support xterm.js. In this case a WebSocket will be connected to Readable and Writeable streams, and resizing will be done through a separate service call.

I'll experiment with creating a tty.WriteStream instance and connecting it to a WebSocket. That could be a more straightforward implementation, but I've never tried instantiating that class.

Copy link
Contributor Author

@lizardruss lizardruss Apr 27, 2019

Choose a reason for hiding this comment

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

Creating a new tty.WriteStream instance has an odd side effect of also writing to stdout. 👎

It's probably better to stick with the NodeJS.WriteStream interface. I'll try making an implementation that can be used with a web socket.

@brendandburns
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 2, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, lizardruss

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 2, 2019
@k8s-ci-robot k8s-ci-robot merged commit e5ec945 into kubernetes-client:master May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants