Repository navigation
feat(kubeconfig): fall back to default kubeconfig loading rules - #688
Merged
Merged
Conversation
Make `--kubeconfig` optional across `longhornctl` commands by aligning kubeconfig resolution with `kubectl` via `client-go`'s `NewDefaultClientConfigLoadingRules` and `NewNonInteractiveDeferredLoadingClientConfig`: 1. Use the explicit `--kubeconfig` file when provided (failing immediately if the specified file does not exist). 2. Fall back to the `KUBECONFIG` environment variable (supporting multi-file path lists). 3. Fall back to `~/.kube/config`, and finally to in-cluster configuration when available. Longhorn 14594 Signed-off-by: Derek Su <derek.su@suse.com>
|
This pull request is merged. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change to default kubeconfig discovery.
No open issues 🎉
What changed in this PR
Makes --kubeconfig optional across longhornctl commands by using client-go’s default loading rules, aligning cluster configuration discovery with kubectl.
Changes:
- Resolves configuration from an explicit file,
KUBECONFIGpath lists, the default home file, or in-cluster credentials. - Adds tests for loading precedence and missing-file errors.
- Updates flag defaults, help text, and command documentation.
| File | Description |
|---|---|
| pkg/utils/kubernetes/client.go | Implements default configuration loading and actionable errors. |
| pkg/utils/kubernetes/client_test.go | Tests configuration precedence and missing-file handling. |
| pkg/utils/cmd.go | Updates shared kubeconfig flag help. |
| pkg/consts/environment.go | Removes the redundant kubeconfig environment constant. |
| docs/longhornctl.md | Documents default kubeconfig discovery. |
| docs/longhornctl_version.md | Updates inherited kubeconfig help. |
| docs/longhornctl_trim.md | Updates trimming command help. |
| docs/longhornctl_trim_volume.md | Updates volume trimming help. |
| docs/longhornctl_install.md | Updates installation command help. |
| docs/longhornctl_install_preflight.md | Updates preflight installation help. |
| docs/longhornctl_install_preflight_stop.md | Updates preflight stop help. |
| docs/longhornctl_global-options.md | Documents kubeconfig fallback in global options. |
| docs/longhornctl_get.md | Updates information-gathering command help. |
| docs/longhornctl_get_replica.md | Updates replica retrieval help. |
| docs/longhornctl_export.md | Updates export command help. |
| docs/longhornctl_export_replica.md | Updates replica export help. |
| docs/longhornctl_export_replica_stop.md | Updates replica export stop help. |
| docs/longhornctl_doc.md | Updates inherited kubeconfig help. |
| docs/longhornctl_diagnose.md | Updates diagnostic command help. |
| docs/longhornctl_checksum.md | Updates checksum command help. |
| docs/longhornctl_checksum_volume.md | Updates volume checksum help. |
| docs/longhornctl_check.md | Updates checking command help. |
| docs/longhornctl_check_preflight.md | Updates preflight checking help. |
| cmd/remote/subcmd/diagnose.go | Updates the diagnostic kubeconfig flag help. |
| cmd/remote/longhornctl.go | Leaves environment resolution to client-go and updates help. |
Review effort: Balanced
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #688 +/- ##
=========================================
+ Coverage 6.91% 7.45% +0.54%
=========================================
Files 57 57
Lines 4440 4453 +13
=========================================
+ Hits 307 332 +25
+ Misses 4133 4121 -12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Which issue(s) this PR fixes:
Issue longhorn/longhorn#14594
What this PR does / why we need it:
Make
--kubeconfigoptional acrosslonghornctlcommands by aligning kubeconfig resolution withkubectlviaclient-go'sNewDefaultClientConfigLoadingRulesandNewNonInteractiveDeferredLoadingClientConfig:--kubeconfigfile when provided (failing immediately if the specified file does not exist).KUBECONFIGenvironment variable (supporting multi-file path lists).~/.kube/config, and finally to in-cluster configuration when available.Special notes for your reviewer:
Additional documentation or context