Skip to content

Conversation

@omarkhammassi
Copy link

This PR adds this ability to specify which context to try to create configuration from.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 30, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: omarkhammassi / name: Omar Khammassi (6bacd2a)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 30, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @omarkhammassi!

It looks like this is your first PR to kubernetes-client/java 🎉. 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/java 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. 😃

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: omarkhammassi
Once this PR has been reviewed and has the lgtm label, please assign yue9944882 for approval by writing /assign @yue9944882 in a comment. For more information see:The Kubernetes Code Review Process.

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

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 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. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 30, 2022
new InputStreamReader(
new FileInputStream(kubeConfig), StandardCharsets.UTF_8.name()))) {
KubeConfig kc = KubeConfig.loadKubeConfig(kubeConfigReader);
KubeConfig kc = KubeConfig.loadKubeConfig(kubeConfigReader, context);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't change this signature, just call kc.setContext(...) after the kube config is created.

Copy link
Member

Choose a reason for hiding this comment

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

+1 keep the parameter list minimal and neat

Copy link
Author

Choose a reason for hiding this comment

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

Done.

return standard(true, context);
}

public static ClientBuilder standard(boolean persistConfig, String context) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than change this signature, I think we should add a context(String context) method to ClientBuilder

Copy link
Author

Choose a reason for hiding this comment

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

Done.

if (context != null) {
kubeConfig.setContext(context);
} else {
String currentContext = (String) configMap.get("current-context");
Copy link
Member

Choose a reason for hiding this comment

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

nit: promote "currrent-context" to a static final variable in this class

Copy link
Author

Choose a reason for hiding this comment

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

Done.

new InputStreamReader(
new FileInputStream(kubeConfig), StandardCharsets.UTF_8.name()))) {
KubeConfig kc = KubeConfig.loadKubeConfig(kubeConfigReader);
KubeConfig kc = KubeConfig.loadKubeConfig(kubeConfigReader, context);
Copy link
Member

Choose a reason for hiding this comment

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

+1 keep the parameter list minimal and neat

@omarkhammassi omarkhammassi requested review from brendandburns and yue9944882 and removed request for brendandburns and yue9944882 August 31, 2022 11:19

public static ClientBuilder context(String context) throws IOException {
final File kubeConfig = getKubeConfigFile();
ClientBuilder clientBuilder = getClientBuilder(true, kubeConfig, context);
Copy link
Contributor

@brendandburns brendandburns Sep 1, 2022

Choose a reason for hiding this comment

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

Don't change the signature here, just call kubeconfig.setContext(context) before you call getClientBuilder(context)

Copy link
Author

Choose a reason for hiding this comment

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

kubeConfig is of type File , setContext(context) can only be set at a later stage when building the client

}

private static ClientBuilder getClientBuilder(boolean persistConfig, File kubeConfig)
private static File getKubeConfigFile() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is messy. We should really refactor the whole ClientBuilder class so that it defers all of this construction until the build() method is called.

That's beyond the scope of this PR though (unless you want to :)) but please add a TODO: defer construction to build() method here.

}

public static ClientBuilder context(String context) throws IOException {
final File kubeConfig = getKubeConfigFile();
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't quite what I was expecting, I think that we should support ClientBuilder.standard().context("foo").build() as well as ClientBuilder.kubeconfig(someFile).context("foo").build()

I think what this means is that we need to save off the KubeConfig object in the builder rather than constructing it new each time.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 1, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 31, 2022
@brendandburns
Copy link
Contributor

Closing this PR as stale, please feel free to re-open it if you plan to work on it further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. 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.

5 participants