Skip to content

Prevent NullReferenceException when using HttpClient to initialize Kubernetes client. Fixes #335 #336

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

Merged
merged 2 commits into from
Jan 7, 2020

Conversation

BrandonSharp
Copy link
Contributor

This should correct the NullReferenceException that occurs when passing in an HttpClient to the constructor of the Kubernetes client. This occurred because HttpClient objects are already initialized with an HttpClientHandler before being handed down to the Kubernetes client, and there's no way to retrieve that object from an HttpClient once initialized.

Because it's useful to set some values on an HttpClientHandler based on the Kubernetes configuration, I added a new file to the partial KubernetesClientConfiguration class that handles generation of a default HttpClientHandler based on the config. This replaced the need to call InitializeFromConfig in the Kubernetes.ConfigInit.cs class from the constructor that accepts an HttpClient. I've also updated the example named httpClientFactory to illustrate the use of this new function.

I also split the SetCredentials method in Kubernetes.ConfgInit.cs into two separate functions. Originally, this method was both setting credentials, and adding certificates to the HttpClientHandler. Because of the changes required to resolve this bug, it was necessary to pull the certificate related code out, and make it more generally usable, given an HttpClientHandler and a config object.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 19, 2019
@k8s-ci-robot
Copy link
Contributor

Welcome @BrandonSharp!

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 Dec 19, 2019
@BrandonSharp
Copy link
Contributor Author

Rebased my fork to pick up the recent changes in master that seems to have addressed some of the failing tests.

@brendandburns
Copy link
Contributor

Sorry for the delay here, holidays got in the way, I will try to review in the next day or so.

Thanks for the patience.

@brendandburns
Copy link
Contributor

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Jan 7, 2020
@k8s-ci-robot k8s-ci-robot merged commit 3a30033 into kubernetes-client:master Jan 7, 2020
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.

3 participants