Prevent NullReferenceException when using HttpClient to initialize Kubernetes client. Fixes #335 #336
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.
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 namedhttpClientFactory
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.