danielfoehrKn / kubeswitch

The kubectx for operators.
https://danielfoehrkn.medium.com/the-case-of-kubeswitch-aff4b6a04ae7
Apache License 2.0
832 stars 80 forks source link

Question: kubeswitch print only shortened context name? #18

Closed rbo closed 3 years ago

rbo commented 3 years ago

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

danielfoehrKn commented 3 years ago

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

rbo commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

LGTM

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

danielfoehrKn commented 3 years ago

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

rbo commented 3 years ago

Ah thanks, but the left part is still shortened.

danielfoehrKn commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

should be fixed with this commit

Let me know if that works for you :)

rbo commented 3 years ago

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$
rbo commented 3 years ago

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

danielfoehrKn commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Done, i guess we can close this Issue.

Thank you very much for your support!