derailed / k9s

šŸ¶ Kubernetes CLI To Manage Your Clusters In Style!
https://k9scli.io
Apache License 2.0
26.92k stars 1.69k forks source link

Starting with context param gives runtime error #2388

Closed duplabe closed 9 months ago

duplabe commented 9 months ago




Describe the bug Starting k9s with a valid kubeconfig context (--context) gives Boom!! runtime error: invalid memory address or nil pointer dereference.

To Reproduce Steps to reproduce the behavior:

$ k config get-contexts -o name
...
k8s

$ k9s --context k8s
 ____  __.________
|    |/ _/   __   \______
|      < \____    /  ___/
|    |  \   /    /\___ \
|____|__ \ /____//____  >
        \/            \/

Boom!! runtime error: invalid memory address or nil pointer dereference.

Expected behavior

Start k9s with the given context. Starting without the --context param works as expected.

Versions (please complete the following information):

Additional context This bug came up with the 0.30.0 update

Logs:

6:52PM INF šŸ¶ K9s starting up...
6:52PM ERR Boom! runtime error: invalid memory address or nil pointer dereference
6:52PM ERR goroutine 1 [running]:
runtime/debug.Stack()
    runtime/debug/stack.go:24 +0x64
github.com/derailed/k9s/cmd.run.func2()
    github.com/derailed/k9s/cmd/root.go:84 +0x9c
panic({0x1046b8460?, 0x106bccea0?})
    runtime/panic.go:914 +0x218
github.com/derailed/k9s/internal/client.(*Config).CurrentClusterName(0x0?)
    github.com/derailed/k9s/internal/client/config.go:101 +0xd4
github.com/derailed/k9s/internal/config/data.(*Context).Validate(0x14000d33f40, {0x0, 0x0}, {0x104c63620?, 0x14000da0d90})
    github.com/derailed/k9s/internal/config/data/context.go:51 +0x74
github.com/derailed/k9s/internal/config/data.(*Config).Validate(...)
    github.com/derailed/k9s/internal/config/data/config.go:28
github.com/derailed/k9s/internal/config/data.(*Dir).loadConfig(0x14000bc38a8, {0x14000ad7130?, 0x0?})
    github.com/derailed/k9s/internal/config/data/dir.go:76 +0xa8
github.com/derailed/k9s/internal/config/data.Dir.Load({{0x1400100aa40, 0x3c}, {0x0, 0x0}, {0x104c63620, 0x14000da0d90}}, {0x16efa755e, 0x3}, 0x14000d33ef0)
    github.com/derailed/k9s/internal/config/data/dir.go:51 +0x234
github.com/derailed/k9s/internal/config.(*K9s).ActivateContext(0x140007900f0, {0x16efa755e, 0x3})
    github.com/derailed/k9s/internal/config/k9s.go:181 +0xb8
github.com/derailed/k9s/internal/config.(*Config).Refine(0x14001001e90, 0x14000e3b440, 0x14000a32de0, 0x14000da0d90?)
    github.com/derailed/k9s/internal/config/config.go:72 +0x48
github.com/derailed/k9s/cmd.loadConfiguration()
    github.com/derailed/k9s/cmd/root.go:117 +0x1b0
github.com/derailed/k9s/cmd.run(0x14000b6a900?, {0x10371d3bf?, 0x4?, 0x10371d2db?})
    github.com/derailed/k9s/cmd/root.go:94 +0x380
github.com/spf13/cobra.(*Command).execute(0x106bffd40, {0x140001922e0, 0x2, 0x2})
    github.com/spf13/cobra@v1.8.0/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x106bffd40)
    github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
    github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/derailed/k9s/cmd.Execute(...)
    github.com/derailed/k9s/cmd/root.go:59
main.main()
    github.com/derailed/k9s/main.go:32 +0x28
derailed commented 9 months ago

@duplabe Thank you for this report! Could you include k9s debug logs? Tx!

duplabe commented 9 months ago

@derailed I've added the logs.

Additional info: I usually clear my current-context with kubectx -u to prevent any accidental change on my clusters. I only get the error I reported when the current-context is empty.

Eg.:

$ kubectx k8s
Switched to context "k8s".

$ k9s --context k8s

# starting without error

$ kubectx -u
Unsetting current context.
Property "current-context" unset.

$ k9s --context k8s
 ____  __.________
|    |/ _/   __   \______
|      < \____    /  ___/
|    |  \   /    /\___ \
|____|__ \ /____//____  >
        \/            \/

Boom!! runtime error: invalid memory address or nil pointer dereference.

$ kubectx ip-dev
Switched to context "ip-dev".

$ k9s --context k8s

# starting without error, with the k8s context

$ kubectx -u
Unsetting current context.
Property "current-context" unset.

$ k9s

# starting without error, and with the context selector

$ k9s --context k8s
 ____  __.________
|    |/ _/   __   \______
|      < \____    /  ___/
|    |  \   /    /\___ \
|____|__ \ /____//____  >
        \/            \/

Boom!! runtime error: invalid memory address or nil pointer dereference.
duplabe commented 9 months ago

I tried 0.30.4 and looks like https://github.com/derailed/k9s/pull/2386 solved this issue also, so I'm closing this. Thanks!