gtsystem / lightkube

Modern lightweight kubernetes module for python
https://lightkube.readthedocs.io
MIT License
109 stars 13 forks source link

Cannot set Client trust_env=False #19

Closed addyess closed 2 years ago

addyess commented 2 years ago

httpx client created here doesn't allow override of the trust_env keyword option.

Please consider some generic **kwargs for configuration of the client. httpx.Client will probably continue to expand its constructor here

addyess commented 2 years ago

Workaround ?


# Quick hack to set `trust_env=False` on the httpx client,
# so that it ignores env *_proxy settings.
from lightkube.core.generic_client import GenericClient
from lightkube.config.client_adapter import httpx_parameters
from lightkube.config.kubeconfig import SingleConfig
import httpx

def CustomClient(config: SingleConfig, timeout: httpx.Timeout) -> httpx.Client:
    return httpx.Client(trust_env=False, **httpx_parameters(config, timeout))

GenericClient.AdapterClient = staticmethod(CustomClient)
# -------------------------------------------------------------------------------------------
gtsystem commented 2 years ago

I don't have specific concerns to support the trust_env parameter (and you can create a PR for that), but I would like to avoid the generic kwargs: lightkube like httpx attempts to offer a clear and typed interface to end users, so that it's easier to use and more errors can be caught before runtime. Furthermore not all httpx.Client parameters make sense for a k8s client nor we can allow to override parameters that are generated from kubeconfig and needed for proper authentication.

addyess commented 2 years ago

i can agree with this style. I will adjust my https://github.com/gtsystem/lightkube/pull/20 tomorrow to meet this request. Thanks for the great library.

addyess commented 2 years ago

Updated. thanks for the review @gtsystem

gtsystem commented 2 years ago

Released as part of v0.10.0