Skip to content

Add BuildDefaultConfig overload to override current context (#1730) - #1917

Open
dgates82 wants to merge 2 commits into
kubernetes-client:masterfrom
dgates82:1730-builddefaultconfig-context-override
Open

dgates82 wants to merge 2 commits into
kubernetes-client:masterfrom
dgates82:1730-builddefaultconfig-context-override

Conversation

@dgates82

Copy link
Copy Markdown

Summary

Closes #1730. Adds BuildDefaultConfig(string currentContext). The existing zero-arg BuildDefaultConfig() already resolved a kubeconfig from KUBECONFIG (including multi-file merges), the default file location, or in-cluster config, but had no way to override which context got used, even though the object/file-based builders it delegates to already supported one. Follows the overload approach @brendandburns confirmed in the issue.

@GaTTGeng mentioned interest in taking this earlier but no PR followed, happy to close this in favor of theirs if it's already in progress.

Validation

Added a test verifying the override is honored against a merged multi-file KUBECONFIG config specifically, since that's the scenario in the original issue. Full existing test suite passes alongside it.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: dgates82 / name: dgates82 (8d448ba)

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Sep 24, 2026
@kubernetes-prow

Copy link
Copy Markdown

Welcome @dgates82!

It looks like this is your first PR to kubernetes-client/csharp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/csharp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 24, 2026
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 24, 2026
@tg123
tg123 requested a balanced review from Copilot September 28, 2026 07:35
@tg123 tg123 self-assigned this Sep 28, 2026

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.

Copilot review overview

🟡 Changes recommended

The equivalent AOT configuration API does not expose the new overload.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds context overrides when building default kubeconfig configurations, including merged KUBECONFIG files.

Changes:

  • Adds BuildDefaultConfig(string currentContext).
  • Tests context selection with multi-file configuration.
File Description
src/​KubernetesClient/​KubernetesClientConfiguration.ConfigFile.cs Adds and delegates the context overload.
tests/​KubernetesClient.Tests/​KubernetesClientConfigurationTests.cs Verifies the override against merged configuration.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@brendandburns brendandburns 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.

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 3, 2026
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, dgates82

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

@kubernetes-prow kubernetes-prow Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 3, 2026
@kubernetes-prow

Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@dgates82
dgates82 force-pushed the 1730-builddefaultconfig-context-override branch from 235ab00 to 743bf3b Compare November 5, 2026 13:20
@kubernetes-prow kubernetes-prow Bot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 5, 2026
@kubernetes-prow

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@dgates82

dgates82 commented Nov 5, 2026

Copy link
Copy Markdown
Author

Rebased onto master after #1930. BuildDefaultConfig(string) now forwards to a new BuildDefaultConfig(string, ExecCredentialPluginPolicy), so a context override doesn’t bypass the exec plugin policy. The AOT copy is updated to match. Tests pass locally.

@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 5, 2026

This branch has not been deployed

No deployments
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.

BuildDefaultConfig should support specifying a context when using multi-file KUBECONFIG

4 participants