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

kubeswitcher.1m.sh: issue with profile or environment variables? Plugin only works if xbar is launched via terminal #1922

Closed
brunopereira7 opened this issue Mar 2, 2023 · 11 comments
Labels

Comments

@brunopereira7
Copy link

OS: MacOS - Ventura 13.2.1
Processor: Apple M1
xbar version: 2.1.7-beta
plugin: kubeswitcher.1m.sh by Elias Abacioglu (@Raboo on GitHub)

Description: I'm not sure if the issue could be related to xbar itself, or even something that I'm missing, but I'm trying to set up xbar with 'Kubeconfig Namespace & Context Switcher' plugin, and it's not working as expected when xbar is launched via a standard application.

For detailed information see: matryer/xbar#877

FYI: @Raboo

@Raboo
Copy link
Contributor

Raboo commented Mar 2, 2023

My xbar is started as a standard application.
Easiest way to troubleshoot the plugin is to execute it directly in a terminal to see the output and to see if there are any errors.

Perhaps even run with bash -x ./plugin.sh for more visibility into what the script does.

@brunopereira7
Copy link
Author

I @Raboo first of all thanks for the plugin and your response.

I didn't add here all the details that you can find -> matryer/xbar#877 but your script seems to be ok if I run it with the terminal:

image

The output seems ok:
image

Unfortunately, I don't understand why it did not work when xbar is launched via applications / or started at login (Namespace and Context empty):

image

image

@Raboo
Copy link
Contributor

Raboo commented Mar 2, 2023

hmm, I don't know why and what would change depending on how you start xbar.
Perhaps it's cause when xbar is started via UI or autostart it doesn't source ~/.profile, ~/.bashrc or ~/.bash_profile.

Try changing line PATH=$PATH:/usr/local/bin to PATH=$PATH:/usr/local/bin:/opt/homebrew/bin in kubeswitcher.sh

I noticed I have both /usr/local/bin/kubectl and /opt/homebrew/bin/kubectl on my laptop, would explain why I haven't encountered this problem.

@brunopereira7
Copy link
Author

I've already tried what you mentioned but unfortunately didn't fix the issue 😞

By the way, a colleague has successfully set up xbar with kubeswitcher plugin; everything works out of the box with the following setup:
OS: MacOS - Monterrey 12.6.2 (21G320)
Processor: Intel
xbar version: 2.1.7-beta

@Raboo
Copy link
Contributor

Raboo commented Mar 2, 2023

Well I have a M1 Pro running on Ventura and 2.1.7-beta.

Try changing this

KUBECTL=$(command -v kubectl)

to this

KUBECTL=$(/usr/bin/command -v kubectl)

Also are you running kube config (~/.kube/config) in an non-default path (i.e. are you using $KUBECONFIG to configure a different path for your kube config file?)?

@brunopereira7
Copy link
Author

Changing KUBECTL=$(command -v kubectl) to KUBECTL=$(/usr/bin/command -v kubectl) didn't solve the problem on my end.

Concerning kube config, I'm using a non-default path indeed:

└── ~/.kube
    ├── dlc-nonprod.kubecfg
    ├── dlc-prod.kubecfg
    └── sandbox.kubecfg
~echo $KUBECONFIG                                                                                                                                                                                                                       
/Users/miguebru/.kube/sandbox.kubecfg:/Users/miguebru/.kube/dlc-nonprod.kubecfg:/Users/miguebru/.kube/dlc-prod.kubecfg

@Raboo
Copy link
Contributor

Raboo commented Mar 4, 2023

I guess you should add KUBECONFIG=/Users/miguebru/.kube/sandbox.kubecfg:/Users/miguebru/.kube/dlc-nonprod.kubecfg:/Users/miguebru/.kube/dlc-prod.kubecfg to the script.

@sprak3000
Copy link
Sponsor Collaborator

@Raboo

Does #1925 close this issue?

@Raboo
Copy link
Contributor

Raboo commented Mar 10, 2023

@sprak3000 I think so, but @brunopereira7 hasn't answered yet. But I think it should.

@brunopereira7
Copy link
Author

Hey guys, definitely it's weird; I've tested with the last version of the script and even added a new menu entry to debug the env echo "Kubeconfig: ${KUBECONFIG}" but unfortunately, it's not working.

image

As a workaround, I'm simply launching the app via terminal open -a xbar.app and everything works as expected.

@Raboo
Copy link
Contributor

Raboo commented May 15, 2024

#2035 should perhaps close this as it adds ability to inject the KUBECONFIG from the normal bash and zsh places.
However the script seems to have issues to switch between contexts from multiple files now instead (matryer/xbar#877).
I will try to figure it on that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants