-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
[Feature] Add Bash shell support #66
Conversation
Minor refactor. Add getClusterKubeConfigOath() to make logic reusable for later changes.
Refactoring. Make createKubeconfigFile() a stand along function, so we don't have to recreate the file every time we look up the file name.
Move the logic of retrive per cluster kube config file into cli/cluster.go. Simplify the CLI handling code.
Add the basic frame work for supporting spawning a bash shell by cli command. With this change, we can spawn a bash shell in the context of a cluster $ k3d create -n my-cluster $ k3d bash -n my-cluster [my-cluster] $> // execute commands with KUBECONFIG already set up [my-cluster] $> kubectl get pods
OS distribution and user may choose to install bash in different path. This patch uses bash found by "$PATH" environment, rather than hard code the bash path. This patch also handle the case 'bash' are not found. Mostly likely due to bash not being supported by the platform, or it is not installed.
In addition to provide an interactive shell, this patch adds the '--command' and '-c' options to allow user to issue a command in the context of a cluster. For example: $ k3d bash -c 'kubectl cluster-info'
In theory, we can execute 'k3d bash' again within an cluster shell. I can't think of any practical value for allowing this capability. On the contrary, this can lead to confusion to the user. This patch adds a simple mechanism to detect and block recursive bash invocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine for me, although I'd love to have a more generic solution based on $SHELL
instead of only bash.
Can we rename it to k3d shell
and add different implementations as a flag?
E.g. k3d shell --shell zsh
, where bash
is the default value?
Because I don't think we should add additional shells as commands to k3d
@iwilltry42 suggested to group all shell support under and single subcommand -- shell.
Add subshell argument --shell. Currently, support only bash, which is also the default value.
Make sense @iwilltry42. I have implemented the suggestion and updated the PR. Thanks for the review. |
Can we use the Shell from |
I don't think $SHELL is that reliable: On the other hand, if your suggestion is that we always start "$SHELL", I am just not confident the changes in the PR, especially w.r.t. PS1 applies to other shells. I'd rather be conservative since I mostly use bash. I suppose if other shell users find this command useful, we should see more contributions on supporting of other shells -- we can probably generalize it more then. |
I also was hoping for this to be possible. I tried it though and it's not compatible with the changes of this PR. |
After creating a cluster, k3d will display a hint on how to set the KUBECONFIG. Often the message scrolled away, and one has to either remember the syntax or hunt for the message.
This PR implemented the 'bash' subcommand to make switch between cluster context easier.
To start a new shell with a cluster context do:
$ k3d bash -n
This will gave a new shell with KUBECONFIG set for the cluster. kubectl will just work with the intended cluster. Use 'exit' to leave the shell
Also support a one liner use cases:
$ k3d bash -n -e 'kubectl cluster-info'
This is useful to quick issue commands against multiple clusters.
Limitations: