Skip to content

Fix: Prevent crash when kubeconfig context reference null clusters#715

Open
tejhan wants to merge 159 commits into
Azure:headlamp-downstreamfrom
tejhan:fix/kubeconfig-nil-clusters-crash
Open

Fix: Prevent crash when kubeconfig context reference null clusters#715
tejhan wants to merge 159 commits into
Azure:headlamp-downstreamfrom
tejhan:fix/kubeconfig-nil-clusters-crash

Conversation

@tejhan

@tejhan tejhan commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR fixes an issue where if the kubeconfig has contexts but cluster fields set to null. This issue surfaces in 2 ways:

  1. Startup crash: Running AKSD in dev mode fails immediately when loading the kubeconfig.
  2. Runtime crash: Deleting a cluster via an external tool can cause AKSD to crash as well when reading kubeconfig during transition states.

A kubeconfig with both clusters and contexts set to null is safe since we skip calling getCluster but in the case of present contexts & null clusters (which can happen frequently when modifying kubeconfig via external tools), the getCluster logic fails.

The failure was due to it's type assertion that paniced on nil.

To resolve this, implemented an ok assertion, falling in line with existing handler logic we have in the getUser function.

Now when a context references a nil clusters field, an error is returned gracefully and the backend continues running.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • CI/CD changes
  • Other: **___**

Changes Made

  • Use comma ok assertion in getCluster to gracefully return an error on nil
  • Add regression test null_clusters_with_contexts_no_panic and kubeconfig_null_clusters to reproduce malformed kubeconfig

Testing

  1. Modify your kubeconfig to contain a context with cluster:"".
  2. Start AKSD with npm run dev
  3. Observe successful startup.

This original issue can be replicated by performing the above steps 1 & 2 and observing a failed startup.

joaquimrocha and others added 30 commits February 25, 2026 13:07
Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
So it just uses the name.

Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
…mand execution

This improves performance by avoiding repeated shell environment
queries and ensures consistent environment variables across commands.

Co-authored-by: Santhosh Nagaraj <sannagaraj@microsoft.com>

Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
… execution

This enables AKS Desktop plugin functionality and improves command
execution by using the cached shell environment for better PATH
resolution and consistent environment variables.

Co-authored-by: Santhosh Nagaraj <sannagaraj@microsoft.com>

Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
…ugin integration

This extends the frontend to support kubectl commands and integrates
the AKS Desktop plugin with proper permission handling and command
execution capabilities.

Co-authored-by: Santhosh Nagaraj <sannagaraj@microsoft.com>

Signed-off-by: Joaquim Rocha <joaquim.rocha@microsoft.com>
this patch updates the product name which
affects the final binary name

Signed-off-by: yolossn <sannagaraj@microsoft.com>
this patch removes the initialise in the app
start since it was blocking the rendering process
in windows. This is fixed by calling the
getShellEnvironment in runCmd and make sure
getShellEnvironment caches the values instead
of running on each call

Signed-off-by: yolossn <sannagaraj@microsoft.com>
this patch adds consent to aks-desktop specific
commands by default to avoid the user consent
popups

Signed-off-by: yolossn <sannagaraj@microsoft.com>
Signed-off-by: yolossn <sannagaraj@microsoft.com>
…native

So we're more compatible with different platforms.
sniok and others added 16 commits March 20, 2026 12:27
frontend: EditorDialog: Ensure editor is visible on high zoom by providing proper scrolling
…-section-truncation

frontend:Resource: Fix ConditionsTable truncation on resize
Removed previous Empty change for no data announce, because
it works on windows narrator not nvda, and otherwise it would
double announce.
frontend: Table: SimpleTable: Fix announce of no data
SimpleTable: Remove hidden overflow for table cells
i18n: Distribute latest translations
upstreamable: resourceMap: group unscheduled pods in node view
frontend: Add AppInsights connection string
…ening

aksd: harden App Insights telemetry to anonymous app-usage counts
frontend: Reenable i18n LanguageDetector
@tejhan tejhan self-assigned this Jun 3, 2026
Copilot AI review requested due to automatic review settings June 3, 2026 23:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request hardens kubeconfig parsing in the backend to avoid panics when the kubeconfig contains contexts but the top-level clusters field is null/missing, returning a normal error instead so the process can continue running.

Changes:

  • Replaced the unsafe type assertion in getCluster with a comma-ok assertion.
  • Returns a graceful error when kubeconfig["clusters"] is missing/invalid instead of panicking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/pkg/kubeconfig/kubeconfig.go
@tejhan
tejhan force-pushed the fix/kubeconfig-nil-clusters-crash branch from 46e4c62 to 992e589 Compare June 4, 2026 15:08
@tejhan
tejhan requested a review from Copilot June 4, 2026 15:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread backend/pkg/kubeconfig/kubeconfig_test.go
…ull clusters

Signed-off-by: tejhan-diallo <tejhan.diallo@gmail.com>
@tejhan
tejhan force-pushed the fix/kubeconfig-nil-clusters-crash branch from 992e589 to b6c045a Compare June 4, 2026 15:20
@tejhan
tejhan requested a review from Copilot June 4, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@sniok
sniok force-pushed the headlamp-downstream branch from c1420ee to 551275e Compare July 1, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants