Repository navigation
fix(desktop): don't crash when Prometheus discovery runs without a kubeconfig - #1787
Merged
Merged
Conversation
…beconfig Desktop stays up when kubeconfig init fails so the user can see the error, but bootstrap still handed the Prometheus and traffic subsystems k8s.GetClient() — a nil *Clientset that becomes a non-nil kubernetes.Interface. The "no client" guard in discovery never fired, and the first surface to kick discovery (Settings overview, Cost page, via /api/opencost/summary) dereferenced it inside a discovery goroutine, where no HTTP recoverer could catch the panic. The process died. Add k8s.GetClientInterface(), which returns an untyped nil when no client exists, and use it at every bootstrap site that stores the client in an interface. Fixes #1782
PR Summary by QodoPrevent desktop crash when kubeconfig is unavailable
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can group findings by type and pick your Finding display, from Minimal to Full |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
RegisterCallbacksstill passedk8s.GetClient()— a nil*kubernetes.Clientset— intoprometheuspkg.Initialize/Reinitialize/traffic.ReinitializeWithConfig, all of which takekubernetes.Interface. A typed nil in an interface is non-nil, so thek8sClient == nilguard indiscover()never fired./api/opencost/summary→EnsureConnected→prom.Discoverthen dereferenced it inside awg.Goworker, 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.Verified
make desktop-binary+ empty$HOME: click Settings →panic: nil pointer dereferenceinpkg/prom.collectWellKnownLocations, process gone./api/opencost/summarywith{"available":false,"reason":"query_error",…}andPOST /api/prometheus/connectwithno Kubernetes client available for discovery; the process stays up.go test ./internal/k8s ./internal/prometheus ./internal/appandpkg/promgreen.🤖 Generated with Claude Code
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.Clientsetstored inkubernetes.Interface, so downstreamclient == nilchecks 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 inRegisterCallbacksto use it instead ofGetClient(). Regression tests lock in untyped-nil vs pass-through behavior.Reviewed by Cursor Bugbot for commit 6edb345. Bugbot is set up for automated code reviews on this repo. Configure here.