Skip to content

Commit

Permalink
Support custom httpx transports
Browse files Browse the repository at this point in the history
  • Loading branch information
XeCycle authored and gtsystem committed Nov 6, 2024
1 parent a1356fe commit efd0cb6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
18 changes: 14 additions & 4 deletions lightkube/config/client_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@


def Client(
config: SingleConfig, timeout: httpx.Timeout, trust_env: bool = True
config: SingleConfig,
timeout: httpx.Timeout,
trust_env: bool = True,
transport: httpx.BaseTransport = None,
) -> httpx.Client:
return httpx.Client(**httpx_parameters(config, timeout, trust_env))
return httpx.Client(
transport=transport, **httpx_parameters(config, timeout, trust_env)
)


def AsyncClient(
config: SingleConfig, timeout: httpx.Timeout, trust_env: bool = True
config: SingleConfig,
timeout: httpx.Timeout,
trust_env: bool = True,
transport: httpx.AsyncBaseTransport = None,
) -> httpx.AsyncClient:
return httpx.AsyncClient(**httpx_parameters(config, timeout, trust_env))
return httpx.AsyncClient(
transport=transport, **httpx_parameters(config, timeout, trust_env)
)


def httpx_parameters(config: SingleConfig, timeout: httpx.Timeout, trust_env: bool):
Expand Down
3 changes: 3 additions & 0 deletions lightkube/core/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AsyncClient:
* **dry_run** - *(optional)* Apply server-side dry-run and guarantee that modifications will not
be persisted in storage. Setting this field to `True` is equivalent of passing `--dry-run=server`
to `kubectl` commands.
* **transport** - *(optional)* Custom httpx transport
"""

def __init__(
Expand All @@ -58,6 +59,7 @@ def __init__(
field_manager: str = None,
trust_env: bool = True,
dry_run: bool = False,
transport: httpx.AsyncBaseTransport = None,
):
self._client = GenericAsyncClient(
config,
Expand All @@ -67,6 +69,7 @@ def __init__(
field_manager=field_manager,
trust_env=trust_env,
dry_run=dry_run,
transport=transport,
)

@property
Expand Down
3 changes: 3 additions & 0 deletions lightkube/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Client:
* **dry_run** - *(optional)* Apply server-side dry-run and guarantee that modifications will not
be persisted in storage. Setting this field to `True` is equivalent of passing `--dry-run=server`
to `kubectl` commands.
* **transport** - *(optional)* Custom httpx transport
"""

def __init__(
Expand All @@ -63,6 +64,7 @@ def __init__(
field_manager: str = None,
trust_env: bool = True,
dry_run: bool = False,
transport: httpx.BaseTransport = None,
):
self._client = GenericSyncClient(
config,
Expand All @@ -72,6 +74,7 @@ def __init__(
field_manager=field_manager,
trust_env=trust_env,
dry_run=dry_run,
transport=transport,
)

@property
Expand Down
5 changes: 4 additions & 1 deletion lightkube/core/generic_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(
trust_env: bool = True,
field_manager: str = None,
dry_run: bool = False,
transport: Union[httpx.BaseTransport, httpx.AsyncBaseTransport] = None,
):
self._timeout = httpx.Timeout(10) if timeout is None else timeout
self._watch_timeout = httpx.Timeout(self._timeout)
Expand All @@ -97,7 +98,9 @@ def __init__(
config = config.get()

self.config = config
self._client = self.AdapterClient(config, timeout, trust_env=trust_env)
self._client = self.AdapterClient(
config, timeout, trust_env=trust_env, transport=transport
)
self._field_manager = field_manager
self._dry_run = dry_run
self.namespace = namespace if namespace else config.namespace
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='lightkube',
version="0.15.4",
version="0.15.5",
description='Lightweight kubernetes client library',
long_description=Path("README.md").read_text(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit efd0cb6

Please sign in to comment.