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

New plugin to create a terminal in the context you are watching #2748

Closed
cobcan opened this issue Jun 17, 2024 · 4 comments
Closed

New plugin to create a terminal in the context you are watching #2748

cobcan opened this issue Jun 17, 2024 · 4 comments

Comments

@cobcan
Copy link
Contributor

cobcan commented Jun 17, 2024

Is your feature request related to a problem? Please describe.

The problem is deploying objects in the wrong context because of a mismatch between k9s and the terminal you are using to deploy

Describe the solution you'd like
The solution is a plugin that opens up a terminal and executes ´kubectl config use-context $CONTEXT´ to switch to the context currently visualizing

Describe alternatives you've considered
An alternative, could be to open bash directly without calling the emulator or create a window in the k9s UI directly.

Example of the solution as a plugin:

plugins:
  open-terminal:
    shortCut: Ctrl-T
    confirm: false
    description: Open a terminal in the current context
    scopes:
      - all
    command: /usr/bin/sh
    background: false
    args:
      - -c
      - x-terminal-emulator -e bash -c "kubectl config use-context $CONTEXT && bash"
      # Any terminal emulator can be used, example with tilix:
      #- tilix -e bash -c "kubectl config use-context $CONTEXT && bash"
      # Without calling the emulator
      #- bash -c "kubectl config use-context $CONTEXT && bash"

Screenshot from 2024-06-17 22-19-55

@gberche-orange
Copy link
Contributor

@cobcan FYI, I've just contributed #2789 that also aims are removing friction when switching from k9s to terminal by printing the kubectl command to get currently selected object.

In my case, I'm using k9s over an ssh connection (where opening a new x window is not possible). However, it might be possible to open a new tmux window from a k9s plugin, resulting into the same outcome.

@cobcan
Copy link
Contributor Author

cobcan commented Jul 13, 2024

@gberche-orange Thanks for letting me know! (I will use this plugin, its quite handy when there is no terminal emulator available). My idea with this plugin was to facilitate working with multiple clusters. This way you can work without worrying about deploying/updating an object somewhere else.

I think I could modify the plugin (or add another shortcut) to open the terminal in the same window that k9s is running. That should also work even with SSH.

I will give it a try and give an update.

Again thanks for the info and the feedback ;D

@cobcan
Copy link
Contributor Author

cobcan commented Jul 13, 2024

This change makes the terminal to open in the same shell that is k9s. Keep in mind that this will change the current-context of the system. To use a context per shell we could use kubech (https://github.com/DevOpsHiveHQ/kubech) but this will need to install the program.

plugins:
  open-terminal:
    shortCut: Ctrl-T
    confirm: false
    description: Open a terminal in the current context
    scopes:
      - all
    command: /usr/bin/sh
    background: false
    args:
      - -c
      -  bash -c "kubectl config use-context $CONTEXT && echo -e \"\e[1;42mk9s bash terminal.\nCtrl + d or 'exit' to go back to k9s\e[0m\" && bash"

@cobcan
Copy link
Contributor Author

cobcan commented Jul 13, 2024

added this PR: #2795

@cobcan cobcan closed this as completed Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants