-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Describe the bug
I upgraded from 0.9.3 to 0.13.2 and now k9s is crashing a little while after starting up:
____ __.________
| |/ _/ __ \______
| < \____ / ___/
| | \ / /\___ \
|____|__ \ /____//____ >
\/ \/
Boom!! runtime error: invalid memory address or nil pointer dereference.
This wasn't happening before I upgraded.
To Reproduce
Steps to reproduce the behavior:
- User doesn't have permission to list nodes
- Just run
k9sas usual - Crash happens a few moments after startup
Expected behavior
No crashes, hopefully π
Versions (please complete the following information):
- OS: OSX
- K9s 0.13.2
- K8s 1.16.2
Additional context
I have debugged the code and can see the nil pointer deference comes from this line of code: https://github.com/derailed/k9s/blob/master/internal/client/metrics.go#L44 on which nos is nil.
Going a bit up the call stack, the CanI() func returns auth = false and err = list access denied for user on "":v1/nodes the first time it's called, but auth = false and err = nil on following calls.
Then checking APIClient.CanI() I can see the reason it's not returning the error the second time is that it caches the result here, but doesn't return an error when auth = false which is a different behaviour of here.
So either the CanI() func should return consistent results regardless if the value is cached or not or the code in the ClusterLoad() func should handle a nil *v1.NodeList (preferably?), or both?
I was able to get rid of the crash by using either of these methods. I'm not familiar with the codebase, so not sure what would be the best approach here.