Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use value from ContextDetails to populate Namespace #373

Merged
merged 2 commits into from
Mar 17, 2020

Conversation

rynowak
Copy link
Contributor

@rynowak rynowak commented Mar 16, 2020

Use value from ContextDetails to populate Namespace

Fixes: #372

This change uses the value from ContextDetails.Namespace to populate
KubernetesClientConfiguration.Namespace.

The issue is there's a Namespace property on both Context and ContextDetails

  • The property on Context is used today
  • The property on ContextDetails is not
  • The property on ContextDetails maps to the actual yaml config

Obsolete Context.Namespace

I did a separate commit for this so we can skip it if you don't want it. Reasonable people disagree on whether its good semver to obsolete something in a patch/minor release. I'd like some confirmation as well about whether this property is supposed to be there for some reason

This property doesn't map to anything in the YAML and thus will never be
set. Other clients I checked (java, golang) don't look for a property
at this level.

I think this was likely a mistake, and it should be obsoleted because
it will never be populated.

Example:

contexts:
- context:
    cluster: ...
    namespace: ... # this is ContextDetails.Namespace
    user: ...
  name: foo
contexts:
- context:
    cluster: ...
    namespace: ...
    user: ...
  name: foo
  namespace: ... # this is Context.Namespace

@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 Mar 16, 2020
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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/test-infra repository. I understand the commands that are listed here.

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

Welcome @rynowak!

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. 😃

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 16, 2020
@rynowak
Copy link
Contributor Author

rynowak commented Mar 16, 2020

I signed it

@k8s-ci-robot k8s-ci-robot 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 Mar 16, 2020
@rynowak
Copy link
Contributor Author

rynowak commented Mar 16, 2020

/assign @brendandburns

// This serves as validation for any of the properties of ContextDetails being set.
// Other locations in code assume that ContextDetails is non-null.
throw new KubeConfigException($"Cluster not set for context `{currentContext}` in kubeconfig");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this validation because I see a bunch of code running after this at assumes activeContext.ContextDetails is null, and it will crash with a null-ref based on invalid config data.

This is a fix for: kubernetes-client#372

This change uses the value from ContextDetails.Namespace to populate
KubernetesClientConfiguration.Namespace.

The issue is there's a Namespace property on both Context and ContextDetails
 - The property on Context is used today
 - The property on ContextDetails is not
 - The property on ContextDetails maps to the actual yaml config
This property doesn't map to anything in the YAML and thus will never be
set. Other clients I checked (java, golang) don't look for a property
at this level.

I think this was likely a mistake, and it should be obsoleted because
it will never be populated.

Example:

```yaml
contexts:
- context:
    cluster: ...
    namespace: ... # this is ContextDetails.Namespace
    user: ...
  name: foo
```

```yaml
contexts:
- context:
    cluster: ...
    namespace: ...
    user: ...
  name: foo
  namespace: ... # this is Context.Namespace
```
@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 Mar 16, 2020
@tg123
Copy link
Member

tg123 commented Mar 16, 2020

/LGTM

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 16, 2020
@brendandburns
Copy link
Contributor

/lgtm
/approve

Thanks for the PR!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 17, 2020
@k8s-ci-robot k8s-ci-robot merged commit da3bff5 into kubernetes-client:master Mar 17, 2020
@rynowak rynowak deleted the rynowak/fix-372 branch March 17, 2020 22:08
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

KubernetesClientConfiguration.BuildDefaultConfig() does not populate namespace of the current context
4 participants