devlinx9 / plugin-k8s-cluster-cxts-stbar

This is an intellij idea plugin that allows to see the current context for K8s in the status bar
1 stars 2 forks source link

Cannot run program "kubectl" #1

Open ainjayla opened 9 months ago

ainjayla commented 9 months ago

Environment: MacOS (13.6.3 (22G436) + IDEA Build #IU-233.13135.103, built on December 20, 2023 kubectl is installed and running normally in terminal (/usr/local/bin)

Exception: co.com.devlinx9.k8scontextstatusbar.ContextK8sException: java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.updateContextK8s(CurrentContextStatusBarWidget.java:157) at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.onChosen(CurrentContextStatusBarWidget.java:135) at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.onChosen(CurrentContextStatusBarWidget.java:127) at com.intellij.ui.popup.list.ListPopupImpl._handleSelect(ListPopupImpl.java:502) at com.intellij.ui.popup.list.ListPopupImpl.handleSelect(ListPopupImpl.java:449) at com.intellij.ui.popup.list.ListPopupImpl$MyMouseListener.mouseReleased(ListPopupImpl.java:745) at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:298) at java.desktop/java.awt.Component.processMouseEvent(Component.java:6657) at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3385) at com.intellij.ui.popup.list.ListPopupImpl$MyList.processMouseEvent(ListPopupImpl.java:810) at java.desktop/java.awt.Component.processEvent(Component.java:6422) at java.desktop/java.awt.Container.processEvent(Container.java:2266) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4969) at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4583) at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4524) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310) at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2809) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4855) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:794) at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739) at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:733) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:766) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:764) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:763) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:695) at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.kt:635) at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$10(IdeEventQueue.kt:580) at com.intellij.openapi.application.impl.RwLockHolder.runWithEnabledImplicitRead(RwLockHolder.kt:75) at com.intellij.openapi.application.impl.RwLockHolder.runWithImplicitRead(RwLockHolder.kt:67) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:580) at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:72) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:355) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:354) at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:793) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:354) at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:349) at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1014) at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:114) at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1014) at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:349) at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:848) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:391) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92) Caused by: java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073) at java.base/java.lang.Runtime.exec(Runtime.java:594) at java.base/java.lang.Runtime.exec(Runtime.java:418) at java.base/java.lang.Runtime.exec(Runtime.java:315) at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.updateContextK8s(CurrentContextStatusBarWidget.java:144) ... 55 more Caused by: java.io.IOException: error=2, No such file or directory at java.base/java.lang.ProcessImpl.forkAndExec(Native Method) at java.base/java.lang.ProcessImpl.(ProcessImpl.java:314) at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110) ... 60 more

hollandjake commented 9 months ago

Been doing some digging as this was also affecting myself.

It seems intellij doesn't load your systems $PATH env, and instead uses /usr/bin:/bin:/usr/sbin:/sbin which would explain why it cant see it. (my system has kubectl installed under /opt/homebrew/bin/kubectl.

More bizarre is that it works completely fine in plugin test environment, just not in the built version.

hollandjake commented 9 months ago

If any java devs know of the cause for this (its been a while and I am very rusty) any guidance would be greatly appreciated

devlinx9 commented 1 month ago

I update the version, maybe it works for both of you, if not please write me and I review again

hollandjake commented 3 weeks ago

Hi @devlinx9, just updated to latest version issue is still occurring. Here is the error logs

2024-10-21 09:17:25,678 [  26022] SEVERE - #c.i.i.p.PluginManager - java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory
co.com.devlinx9.k8scontextstatusbar.ContextK8sException: java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory
    at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.updateContextK8s(CurrentContextStatusBarWidget.java:160)
    at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.onChosen(CurrentContextStatusBarWidget.java:135)
    at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.onChosen(CurrentContextStatusBarWidget.java:127)
    at com.intellij.ui.popup.list.ListPopupImpl._handleSelect(ListPopupImpl.java:501)
    at com.intellij.ui.popup.list.ListPopupImpl.handleSelect(ListPopupImpl.java:448)
    at com.intellij.ui.popup.list.ListPopupImpl$MyMouseListener.mouseReleased(ListPopupImpl.java:774)
    at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:298)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6665)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3394)
    at com.intellij.ui.popup.list.ListPopupImpl$MyList.processMouseEvent(ListPopupImpl.java:839)
    at java.desktop/java.awt.Component.processEvent(Component.java:6430)
    at java.desktop/java.awt.Container.processEvent(Container.java:2266)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5035)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4860)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4963)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4577)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4518)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2810)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4860)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:783)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:728)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:755)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:753)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:752)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:696)
    at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.kt:635)
    at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$14(IdeEventQueue.kt:581)
    at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:84)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:581)
    at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:73)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1$1.compute(IdeEventQueue.kt:357)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1$1.compute(IdeEventQueue.kt:356)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:843)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.invoke(IdeEventQueue.kt:356)
    at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.invoke(IdeEventQueue.kt:351)
    at com.intellij.ide.IdeEventQueueKt$performActivity$runnableWithWIL$1.invoke$lambda$0(IdeEventQueue.kt:1035)
    at com.intellij.openapi.application.WriteIntentReadAction.lambda$run$0(WriteIntentReadAction.java:24)
    at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:84)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteIntentReadAction(ApplicationImpl.java:910)
    at com.intellij.openapi.application.WriteIntentReadAction.compute(WriteIntentReadAction.java:55)
    at com.intellij.openapi.application.WriteIntentReadAction.run(WriteIntentReadAction.java:23)
    at com.intellij.ide.IdeEventQueueKt$performActivity$runnableWithWIL$1.invoke(IdeEventQueue.kt:1035)
    at com.intellij.ide.IdeEventQueueKt$performActivity$runnableWithWIL$1.invoke(IdeEventQueue.kt:1035)
    at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1036)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:114)
    at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1036)
    at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$10(IdeEventQueue.kt:351)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:397)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
Caused by: java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089)
    at co.com.devlinx9.k8scontextstatusbar.CurrentContextStatusBarWidget$ContextsPopupStep.updateContextK8s(CurrentContextStatusBarWidget.java:147)
    ... 61 more
Caused by: java.io.IOException: error=2, No such file or directory
    at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:295)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:225)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1126)
    ... 63 more

After some investigation it seems that its ProcessBuilder which is causing issues as it does not use the system PATH by default and instead uses its own. I wonder if this is something in intellij overriding the PATH variable that gets exposed to the plugin?

hollandjake commented 3 weeks ago

just logged out the PATH env on both runIde and in the built zip. runIde is as expected including all the env from my system. the built does not.

Ive come across this article https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/ which suggests that its because intellij does not load the env correctly from .bash_profile and/or .zshrc, unlike the main system