Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

keep compatibility with pykube-ng 20.1.0 #62

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pykube/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
}