k9s complaining about "Plugins load failed" in ghostty on a Mac
I'm seeing the error message in k9s when I start it in my ghostty terminal application on a Mac. When took a look at the logs I'm seeing the following line appear repeatedly:
5:27PM WRN Plugins load failed error="lstat /usr/local/share/k9s/plugins: permission denied"
5:27PM WRN Plugins load failed error="lstat /usr/local/share/k9s/plugins: permission denied"
The /usr/local/share/k9s directory does not exist and in fact, my user does not have permission on /usr/local/share at all.
After a bit of experimenting, I found that this error does not appear when I start k9s in WezTerm.
Further digging got me to realize that the reason for this was that ghostty is setting the XDG_DATA_DIRS environment variable:
XDG_DATA_DIRS=/usr/local/share:/usr/share:/Applications/Ghostty.app/Contents/Resources/ghostty/..
WezTerm does not do that.
When I unset this variable in my ghostty terminal window and re-ran k9s, I did not get the warning about plugin loading failing.
I'm assuming k9s is checking for plugins then in $XDG_DATA_DIR/k9s/plugins but I would think that if it either does not have permission to view that directory (as is the case on my Mac it seems) or the directory does not exist, it should not attempt to load plugins from it... and therefore not produce these warnings. Or is there a different "correct" solution to this? Is the problem on ghostty's side maybe?
@StFS Hum... I specifically set my XDG env vars to avoid these surprises in my shell. Given ghostty is an emulator, I guess I am not surprised that they will set these to some locations. N Not sure what OS you are using but as a rule it might make sense to explicitly set those...
I'm using MacOS.
It looks like it's calling loadDir via this loop, which should skip the directory if it doesn't exist.
I only get the error when I add (e.g.) /opt/testing to XDG_DATA_DIRS, create /opt/testing/k9s/plugins, and set chmod 000 on the parent directory - that is, when the error is permission denied.
I think it's a Good Thing to report an error if the user doesn't have permissions to a plugins directory that exists; however, your permission denied error seems to be that the user doesn't have permissions to /usr/local/share and thus can't look inside to see if k9s/plugins exists. If it had permission to the parent, the existing ErrNotExist check in loadDir would cause it to be skipped silently.
If you expect the k9s user to have access to a particular directory inside of XDG_DATA_DIRS, it's obviously best to make sure the plugin directory exists and is readable, but that doesn't seem to be the case here.
I added this PR to fix it.