Skip to content

aksd: fix: Respect KUBECONFIG env var when writing to kubeconfig#276

Open
tejhan wants to merge 1 commit intoAzure:headlamp-downstreamfrom
tejhan:fix/respect-kubeconfig-env-var
Open

aksd: fix: Respect KUBECONFIG env var when writing to kubeconfig#276
tejhan wants to merge 1 commit intoAzure:headlamp-downstreamfrom
tejhan:fix/respect-kubeconfig-env-var

Conversation

@tejhan
Copy link
Collaborator

@tejhan tejhan commented Feb 20, 2026

Description

When registering an AKS cluster or trying to merge one into the kubeconfig via the project creation screen, the kubeconfig path was hardcoded to ~/.kube/config, ignoring the $KUBECONFIG environment variable. Meaning that a user with $KUBECONFIG set would have their cluster config written to the default location instead. This would happen silently & it's propagation would result in inability to create project or properly merge clusters via AKSD.

This change reads $KUBECONFIG and if it's set, uses the first path in the list (matching kubectl behavior for colon/semicolon-separated paths), falling back to ~/.kube/config only when the variable is unset.

Fixes #294

Type of Change

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • [ x] Code refactoring

How to test:

  1. Set $KUBECONFIG to non-default location
  2. Attempt to create a project where the target cluster is not merged as of yet
  3. Merge the cluster when notified in the project creation screen.

Results should be successful merge & next button is properly enabled.

(If this were to fail, a successful merge message would still appear but the next button would still be disabled due to merge at wrong location.)

@tejhan tejhan self-assigned this Feb 20, 2026
Copilot AI review requested due to automatic review settings February 20, 2026 17:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where the AKS Desktop application was ignoring the $KUBECONFIG environment variable when registering AKS clusters. Previously, the kubeconfig path was hardcoded to ~/.kube/config, which caused cluster configurations to be written to the default location even when users had $KUBECONFIG set to a different path. This resulted in silent failures during project creation when the cluster config was written to the wrong location.

Changes:

  • Modified registerAKSCluster function to respect the $KUBECONFIG environment variable when determining where to write kubeconfig files
  • Uses the first path from $KUBECONFIG (for colon/semicolon-separated paths), falling back to ~/.kube/config when unset

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

@tejhan tejhan force-pushed the fix/respect-kubeconfig-env-var branch from 8ff8fc1 to e105839 Compare February 20, 2026 17:43
@skoeva
Copy link
Collaborator

skoeva commented Feb 23, 2026

(If this were to fail, a successful merge message would still appear but the next button would still be disabled due to merge at wrong location.)

is this a bug? feel free to open an issue for this if so

@tejhan
Copy link
Collaborator Author

tejhan commented Feb 24, 2026

(If this were to fail, a successful merge message would still appear but the next button would still be disabled due to merge at wrong location.)

is this a bug? feel free to open an issue for this if so

Yes, my wording could have been better here- but this is indeed a bug, & that message describes the behavior one would notice without the fix in this PR. (If it hypothetically didn't work). I've just opened an issue with some details to track this. #294

Copy link
Collaborator

@illume illume left a comment

Choose a reason for hiding this comment

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

Thanks for this.

Can you please update the commit message to something like this?

aksd: app: aks-cluster: Respect KUBECONFIG env var when writing to kubeconfig

With the signed-off-by removed, because we're using CLA in this repo.

I linked the issue to the PR.

@illume illume marked this pull request as draft February 25, 2026 10:54
@sniok sniok force-pushed the headlamp-downstream branch from def6222 to 3ed87fa Compare February 26, 2026 15:35
@tejhan tejhan force-pushed the fix/respect-kubeconfig-env-var branch from e105839 to e860d59 Compare February 27, 2026 00:25
@tejhan tejhan marked this pull request as ready for review February 27, 2026 00:57
Copilot AI review requested due to automatic review settings February 27, 2026 00:57
Copy link

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 1 comment.


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

@illume illume added p-none No priority was assigned bug Something isn't working labels Feb 27, 2026
@tejhan tejhan force-pushed the fix/respect-kubeconfig-env-var branch from e860d59 to e6744f4 Compare February 27, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p-none No priority was assigned

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Cluster registration ignores $KUBECONFIG and always writes to ~/.kube/config

4 participants