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

Question: kubeswitch print only shortened context name? #18

Closed
rbo opened this issue May 14, 2021 · 14 comments
Closed

Question: kubeswitch print only shortened context name? #18

rbo opened this issue May 14, 2021 · 14 comments

Comments

@rbo
Copy link

rbo commented May 14, 2021

Hi,

is that only me or is kubeswitch using any shortened context name?

Here an example:

$ kubectx | grep windows-workload                                             <===== Original kubectx 
windows-workload/api-vmw-stormshift-coe-muc-redhat-com:6443/kube:admin
$ grep -B4 'windows-workload/' ~/.kube/config
  - context:
        cluster: api-vmw-stormshift-coe-muc-redhat-com:6443
        namespace: windows-workload
        user: kube:admin/api-vmw-stormshift-coe-muc-redhat-com:6443
    name: windows-workload/api-vmw-stormshift-coe-muc-redhat-com:6443/kube:admin
$ switch list-contexts  | grep windows
$ switch list-contexts  | grep kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
.kube/kube:admin
$

my switch configuration

kind: SwitchConfig
version: v1alpha1
kubeconfigStores:
- kind: filesystem
  paths:
  - ~/.kube/config

switch version

$ switch version
Switch:
		version     : v0.4.1
		build date  : 2021-03-16
		go version  : go1.15.8
		go compiler : gc
		platform    : linux/amd64

I would like to see the whole context name.

Thanks for any advice
Cheers
Robert

@rbo rbo changed the title Question: kubeswitch print only shorts names? Question: kubeswitch print only shortened context name? May 14, 2021
@danielfoehrKn
Copy link
Owner

Thanks for reporting.
Do you have a sanitized version of that kubeconfig so that I can reproduce it?

@rbo
Copy link
Author

rbo commented May 15, 2021

Oh yes of course:

$ cat ~/.kube/config
apiVersion: v1
clusters:
  - cluster:
        insecure-skip-tls-verify: true
        server: https://api.vmw.example.com:6443
    name: api-vmw-example-com:6443
contexts:
  - context:
        cluster: api-vmw-example-com:6443
        namespace: windows-container
        user: kube:admin/api-vmw-example-com:6443
    name: windows-container/api-vmw-example-com:6443/kube:admin
  - context:
        cluster: api-vmw-example-com:6443
        namespace: windows-workload
        user: kube:admin/api-vmw-example-com:6443
    name: windows-workload/api-vmw-example-com:6443/kube:admin
current-context: demo-app/api-demo-openshift-pub:6443/admin
kind: Config
preferences: {}
users:
  - name: kube:admin/api-vmw-example-com:6443
    user:
        token: sha256~A518ZtBiOcuyuYuYWk96-NTgZaJh_vfqomZ-SyXTNpc
$ cat ~/.kube/switch-config.yaml
kind: SwitchConfig
version: v1alpha1
kubeconfigStores:
- kind: filesystem
  id: local
  refreshIndexAfter: 3h
  paths:
  - ~/.kube/config
$ kubectx
windows-container/api-vmw-example-com:6443/kube:admin
windows-workload/api-vmw-example-com:6443/kube:admin
$ switch list-contexts
.kube/kube:admin

@danielfoehrKn
Copy link
Owner

It should be fixed on the current master branch. The problem was the slashes in the context names.

Could you check if it works for you now from the master branch?
Thanks!

@rbo
Copy link
Author

rbo commented May 17, 2021

LGTM

Is it possible to disable the kubeconfig preview on the right side?

@danielfoehrKn
Copy link
Owner

Yep, you can use switch --show-preview false.
I am also working on a flag in the switch-config.

@rbo
Copy link
Author

rbo commented May 17, 2021

Ah thanks, but the left part is still shortened.

@danielfoehrKn
Copy link
Owner

danielfoehrKn commented May 17, 2021

Ah thanks, but the left part is still shortened.

Did you build from the current master?
At least for me it works with your provided example kubeconfig.

switch list-contexts | grep windows
dev/windows-workload/api-vmw-example-com:6443/kube:admin
dev/windows-container/api-vmw-example-com:6443/kube:admin

Also try to remove the cache via rm -rf .kube/switch-state

@rbo
Copy link
Author

rbo commented May 17, 2021

list-contexts works, here what I mean:

image

./switcher_linux_amd64 list-contexts  |grep example
.kube/windows-container/api-vmw-example-com:6443/kube:admin
.kube/windows-workload/api-vmw-example-lloooooooooonnnnnnggggggggggggg-com:6443/kube:admin

@danielfoehrKn
Copy link
Owner

danielfoehrKn commented May 17, 2021

should be fixed with this commit

Let me know if that works for you :)

@rbo
Copy link
Author

rbo commented May 17, 2021

Rebuild from master and looks great!

Yep, you can use switch --show-preview false.
I am also working on a flag in the switch-config.

Just-for-information:

$ ./hack/switch/switcher_linux_amd64 --show-preview false
Error: context with name "false" not found
context with name "false" not found$
  • You have to use --show-preview=false
  • Missing \n after the error message.

@rbo
Copy link
Author

rbo commented May 17, 2021

I have only one kubeconfig in ~/.kube/config it is possible to disable the .kube prefix?

@danielfoehrKn
Copy link
Owner

danielfoehrKn commented May 17, 2021

You have to use --show-preview=false

Only for the switcher binary.
The user interacts with the switch.sh script callable with switch.
This is where you need to use

switch --show-preview false

You can now also achieve the same thing via the config file with the latest master.

@danielfoehrKn
Copy link
Owner

I have only one kubeconfig in ~/.kube/config it is possible to disable the .kube prefix?

I'll have to think about a good way to do that. I guess it makes sense that it is configurable.
Could you open a dedicated issue for it?
Thanks!

@rbo
Copy link
Author

rbo commented May 17, 2021

Done, i guess we can close this Issue.

Thank you very much for your support!

@rbo rbo closed this as completed May 17, 2021
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