diff --git a/pykube/http.py b/pykube/http.py index a755d32..517a2db 100644 --- a/pykube/http.py +++ b/pykube/http.py @@ -275,7 +275,12 @@ def get_kwargs(self, **kwargs) -> dict: if "base" not in kwargs: raise TypeError("unknown API version; base kwarg must be specified.") base = kwargs.pop("base") - bits = [base, version] + if version.startswith("/"): + # for compatibility with pykube-ng 20.1.0 when calling api.get(version="/apis"): + # posixpath.join() was throwing away everything before the first "absolute" path (i.e. starting with a slash) + bits = [version] + else: + bits = [base, version] # Overwrite (default) namespace from context if it was set if "namespace" in kwargs: n = kwargs.pop("namespace") diff --git a/tests/test_http.py b/tests/test_http.py index 5b803bc..5acb23f 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -99,3 +99,21 @@ def test_http_with_oidc_auth(monkeypatch): mock_send.assert_called_once() assert mock_send.call_args[0][0].headers["Authorization"] == "Bearer some-id-token" + + +def test_get_kwargs(): + cfg = KubeConfig.from_file(GOOD_CONFIG_FILE_PATH) + api = HTTPClient(cfg) + + assert api.get_kwargs(version="v1") == { + "timeout": 10, + "url": "http://localhost/api/v1/", + } + assert api.get_kwargs(version="/apis") == { + "timeout": 10, + "url": "http://localhost/apis/", + } + assert api.get_kwargs(version="storage.k8s.io/v1") == { + "timeout": 10, + "url": "http://localhost/apis/storage.k8s.io/v1/", + }