From cda669dc00814d32fffda6bfbca8abb6de9461f8 Mon Sep 17 00:00:00 2001 From: Giuseppe Tribulato Date: Wed, 12 Aug 2026 12:30:38 +0200 Subject: [PATCH] Closes #156 --- pyproject.toml | 2 +- src/lightkube/config/client_adapter.py | 9 +++++++-- tests/test_client_adapter.py | 9 +++++++++ uv.lock | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ddc918f..222317d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "lightkube" -version = "1.0.0" +version = "1.0.1" description = "Lightweight kubernetes client library" readme = "README.md" authors = [ diff --git a/src/lightkube/config/client_adapter.py b/src/lightkube/config/client_adapter.py index ea8d011..406cd74 100644 --- a/src/lightkube/config/client_adapter.py +++ b/src/lightkube/config/client_adapter.py @@ -3,7 +3,7 @@ import os import ssl import subprocess -from dataclasses import asdict, dataclass, field +from dataclasses import dataclass, field, fields from pathlib import Path from typing import AsyncGenerator, Callable, Dict, Generator, List, Mapping, Optional, Sequence, Tuple, overload @@ -14,6 +14,11 @@ from .models import Cluster, FileStr, User, UserExec +def _shallow_asdict(instance) -> dict: + """Return a dataclass's fields without copying their values.""" + return {data_field.name: getattr(instance, data_field.name) for data_field in fields(instance)} + + @dataclass class ConnectionParams: """All connection parameters used by Client and AsyncClient""" @@ -29,7 +34,7 @@ def httpx_params(self, config: SingleConfig) -> dict: assert config.user, "Missing user" verify = verify_cluster(config.cluster, config.user, config.abs_file, trust_env=self.trust_env) auth = user_auth(config.user) - return dict(base_url=base_url, verify=verify, auth=auth, **asdict(self)) + return dict(base_url=base_url, verify=verify, auth=auth, **_shallow_asdict(self)) def Client(config: SingleConfig, conn_parameters: ConnectionParams) -> httpx.Client: diff --git a/tests/test_client_adapter.py b/tests/test_client_adapter.py index a0ace43..b0acb5c 100644 --- a/tests/test_client_adapter.py +++ b/tests/test_client_adapter.py @@ -86,6 +86,15 @@ def test_user_cert_data(): assert Path(certs[1]).read_text() == "key" +def test_connection_params_preserves_transport(): + cfg = single_conf(cluster=models.Cluster(server="https://localhost"), user=models.User(token="token")) + transport = httpx.AsyncHTTPTransport(http2=True) + + params = client_adapter.ConnectionParams(transport=transport).httpx_params(cfg) + + assert params["transport"] is transport + + @unittest.mock.patch("ssl.create_default_context") def test_verify_cluster_ca_and_cert(create_default_context): data_dir = Path(__file__).parent.joinpath("data") diff --git a/uv.lock b/uv.lock index 6ba25e4..f9f77ae 100644 --- a/uv.lock +++ b/uv.lock @@ -632,7 +632,7 @@ wheels = [ [[package]] name = "lightkube" -version = "1.0.0" +version = "1.0.1" source = { editable = "." } dependencies = [ { name = "httpx2", extra = ["http2", "ws"] },