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

Commit 949c4b1

Browse files
authored
keep compatibility with pykube-ng 20.1.0 (#62)
1 parent c38e7ad commit 949c4b1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pykube/http.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ def get_kwargs(self, **kwargs) -> dict:
275275
if "base" not in kwargs:
276276
raise TypeError("unknown API version; base kwarg must be specified.")
277277
base = kwargs.pop("base")
278-
bits = [base, version]
278+
if version.startswith("/"):
279+
# for compatibility with pykube-ng 20.1.0 when calling api.get(version="/apis"):
280+
# posixpath.join() was throwing away everything before the first "absolute" path (i.e. starting with a slash)
281+
bits = [version]
282+
else:
283+
bits = [base, version]
279284
# Overwrite (default) namespace from context if it was set
280285
if "namespace" in kwargs:
281286
n = kwargs.pop("namespace")

tests/test_http.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,21 @@ def test_http_with_oidc_auth(monkeypatch):
9999

100100
mock_send.assert_called_once()
101101
assert mock_send.call_args[0][0].headers["Authorization"] == "Bearer some-id-token"
102+
103+
104+
def test_get_kwargs():
105+
cfg = KubeConfig.from_file(GOOD_CONFIG_FILE_PATH)
106+
api = HTTPClient(cfg)
107+
108+
assert api.get_kwargs(version="v1") == {
109+
"timeout": 10,
110+
"url": "http://localhost/api/v1/",
111+
}
112+
assert api.get_kwargs(version="/apis") == {
113+
"timeout": 10,
114+
"url": "http://localhost/apis/",
115+
}
116+
assert api.get_kwargs(version="storage.k8s.io/v1") == {
117+
"timeout": 10,
118+
"url": "http://localhost/apis/storage.k8s.io/v1/",
119+
}

0 commit comments

Comments
 (0)