Skip to content

fix: Return error from GetDefaultKubeConfigPath instead of calling os.Exit#5509

Merged
illume merged 1 commit into
kubernetes-sigs:mainfrom
YadavAkhileshh:fix/get-default-kubeconfig-path-error-5493
May 21, 2026
Merged

fix: Return error from GetDefaultKubeConfigPath instead of calling os.Exit#5509
illume merged 1 commit into
kubernetes-sigs:mainfrom
YadavAkhileshh:fix/get-default-kubeconfig-path-error-5493

Conversation

@YadavAkhileshh
Copy link
Copy Markdown
Contributor

Summary

GetDefaultKubeConfigPath() in backend/pkg/config/config.go was calling os.Exit(1) directly when it failed to resolve the current OS user. This is a Go anti-pattern for library code utility functions should return errors and let the caller decide how to handle failure.

This PR refactors the function to return (string, error) and updates all callers accordingly.

Related Issue

Fixes #5493

Changes

  • Changed GetDefaultKubeConfigPath() signature from string to (string, error).
  • Replaced os.Exit(1) with a proper error return.
  • Updated all callers in config.go and test files to handle the returned error.

Testing

  1. Run backend tests: cd backend && go test ./pkg/config/... ./pkg/kubeconfig/... ./cmd/...
  2. Start Headlamp normally and verify kubeconfig loads correctly.
  3. Confirm no regression in cluster connection behavior.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 9, 2026
@illume illume requested a review from Copilot May 10, 2026 05:59
Copy link
Copy Markdown
Contributor

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

Refactors the backend config.GetDefaultKubeConfigPath helper to return an error instead of terminating the process, and updates callers/tests to handle the new (string, error) signature. This aligns the config utility layer with Go library best practices and avoids unrecoverable exits during tests or reuse.

Changes:

  • Changed GetDefaultKubeConfigPath() to return (string, error) and removed the direct os.Exit(1) call.
  • Updated setKubeConfigPath and Parse to propagate kubeconfig path resolution errors.
  • Updated backend tests that call GetDefaultKubeConfigPath to handle the returned error.

Reviewed changes

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

File Description
backend/pkg/config/config.go Convert default kubeconfig path resolution to error-returning flow and propagate it through config parsing.
backend/pkg/kubeconfig/kubeconfig_test.go Update integration test to handle new (string, error) signature.
backend/cmd/headlamp_test.go Update tests to resolve kubeconfig path once and pass it through, handling errors.

Comment thread backend/pkg/config/config.go Outdated
Comment thread backend/pkg/config/config.go Outdated
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from d0c92ef to 828512d Compare May 10, 2026 06:53
@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 10, 2026
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from 828512d to ae46855 Compare May 10, 2026 06:56
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 10, 2026
@illume illume requested a review from Copilot May 10, 2026 07:13
Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread backend/pkg/config/config.go
Comment thread backend/cmd/headlamp_test.go Outdated
Comment thread backend/cmd/headlamp_test.go Outdated
Comment thread backend/cmd/headlamp_test.go Outdated
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from ae46855 to e7f0ce4 Compare May 10, 2026 08:15
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 10, 2026
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch 2 times, most recently from 88a8055 to 15e714b Compare May 10, 2026 08:17
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 10, 2026
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from 15e714b to 607bc56 Compare May 10, 2026 08:32
@illume illume requested a review from Copilot May 10, 2026 09:29
Copy link
Copy Markdown
Contributor

@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 working on this.

Looks like the backend tests are failing in CI. Can you check with cd backend && go test ./... and fix the errors?

How to run the backend tests

Run cd backend && go test ./... to see all failures. Fix the failing tests and commit the result.

Copy link
Copy Markdown
Contributor

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 3 out of 3 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor

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

Comment thread backend/cmd/headlamp_test.go Outdated
Copy link
Copy Markdown
Contributor

@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 the contribution.

There are some open Copilot review comments — could you take a look at them? Please mark each one as resolved once you've addressed it.

@illume illume requested a review from Copilot May 11, 2026 15:04
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from a3c744d to ffd24d1 Compare May 16, 2026 10:29
@illume illume requested a review from Copilot May 16, 2026 14:55
Copy link
Copy Markdown
Contributor

@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 the contribution.

Could you take a look at the commit messages in this PR? We follow a Linux kernel style for git commits — see the contributing guide and git log for examples.

Commits that need attention
  • fix: Return error from GetDefaultKubeConfigPath instead of calling os.Exit — Missing area: description prefix — e.g. frontend: HomeButton: Fix so it navigates to home or backend: config: Add enable-dynamic-clusters flag.
Commit guidelines
  • Use atomic commits focused on a single change.
  • Use the title format <area>: <Description of changes> — description must start with a capital letter.
  • Keep the title under 72 characters (soft requirement).
  • Explain the intention and why the change is needed.
  • Make commit titles meaningful and describe what changed.
  • Do not add code that a later commit rewrites; squash or reorder commits instead.
  • Do not include Fixes #NN in commit messages.

Good examples:

  • frontend: HomeButton: Fix so it navigates to home
  • backend: config: Add enable-dynamic-clusters flag

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated no new comments.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 16, 2026
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from ffd24d1 to 41f1ce1 Compare May 16, 2026 19:40
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 16, 2026
@illume illume requested a review from Copilot May 17, 2026 06:34
Copy link
Copy Markdown
Contributor

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

Comment thread backend/pkg/config/config.go
Copy link
Copy Markdown
Contributor

@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 working on this.

Would you mind addressing the open Copilot review comments? Please mark each comment as resolved after addressing it.

@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from 41f1ce1 to 9ab48b4 Compare May 17, 2026 17:44
@illume illume requested a review from Copilot May 17, 2026 18:45
Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread backend/cmd/headlamp_test.go
Comment thread backend/pkg/config/config.go
@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from 9ab48b4 to cb92334 Compare May 17, 2026 19:10
@illume illume requested a review from Copilot May 18, 2026 07:14
Copy link
Copy Markdown
Contributor

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

Comment thread backend/pkg/config/config.go
Copy link
Copy Markdown
Contributor

@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 these changes.

Can you please address the open review comments? Once you've resolved each one, please mark it as resolved.

@YadavAkhileshh YadavAkhileshh force-pushed the fix/get-default-kubeconfig-path-error-5493 branch from cb92334 to 1a2e914 Compare May 18, 2026 19:32
@illume illume requested a review from Copilot May 19, 2026 14:39
Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor

@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!

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: illume, YadavAkhileshh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 21, 2026
@illume illume merged commit a240404 into kubernetes-sigs:main May 21, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetDefaultKubeConfigPath calls os.Exit(1) instead of returning an error

4 participants