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

Commit

Permalink
keep compatibility with pykube-ng 20.1.0 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs authored Apr 1, 2020
1 parent c38e7ad commit 949c4b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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/",
}

0 comments on commit 949c4b1

Please sign in to comment.