Repository navigation
Commit 0da1de7
authored
fix(desktop): don't crash when Prometheus discovery runs without a kubeconfig (#1787)
Fixes #1782
## What
Radar Desktop crashed the moment you opened Settings (or the Cost page)
on a machine with no usable kubeconfig — the exact state a fresh install
lands in.
## Why
Desktop deliberately keeps running when kubeconfig init fails so the UI
can show the error. But `RegisterCallbacks` still passed
`k8s.GetClient()` — a nil `*kubernetes.Clientset` — into
`prometheuspkg.Initialize` / `Reinitialize` /
`traffic.ReinitializeWithConfig`, all of which take
`kubernetes.Interface`. A typed nil in an interface is non-nil, so the
`k8sClient == nil` guard in `discover()` never fired.
`/api/opencost/summary` → `EnsureConnected` → `prom.Discover` then
dereferenced it inside a `wg.Go` worker, where chi's Recoverer can't
catch the panic, and the process exited.
## Fix
- `k8s.GetClientInterface()` returns an untyped nil when there is no
client; used at the three bootstrap sites that store the client in an
interface.
- Regression tests pin the untyped-nil and the pass-through case.
## Verified
- Reproduced on macOS with `make desktop-binary` + empty `$HOME`: click
Settings → `panic: nil pointer dereference` in
`pkg/prom.collectWellKnownLocations`, process gone.
- With the fix, the same build answers `/api/opencost/summary` with
`{"available":false,"reason":"query_error",…}` and `POST
/api/prometheus/connect` with `no Kubernetes client available for
discovery`; the process stays up.
- `go test ./internal/k8s ./internal/prometheus ./internal/app` and
`pkg/prom` green.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Small, targeted change at client handoff sites with tests; no auth or
data-path logic changes beyond preventing nil dereference when the
cluster client is missing.
>
> **Overview**
> Fixes a **Radar Desktop process exit** when kubeconfig init fails but
the UI still runs (e.g. fresh install with no kubeconfig). Opening
Settings or hitting cost/Prometheus APIs could trigger discovery with a
**typed nil** `*kubernetes.Clientset` stored in `kubernetes.Interface`,
so downstream `client == nil` checks never ran and discovery panicked.
>
> Adds **`k8s.GetClientInterface()`**, which returns an **untyped nil**
when there is no clientset, and switches Prometheus/traffic bootstrap
and reinit callbacks in `RegisterCallbacks` to use it instead of
`GetClient()`. **Regression tests** lock in untyped-nil vs pass-through
behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
6edb345. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 4b9f2e2 commit 0da1de7
3 files changed
Lines changed: 42 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
| 284 | + | |
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
| 329 | + | |
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
732 | 732 | | |
733 | 733 | | |
734 | 734 | | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
735 | 748 | | |
736 | 749 | | |
737 | 750 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
0 commit comments