Skip to content

Commit

Permalink
k8s: upgrade api clients to networking/v1 API
Browse files Browse the repository at this point in the history
- set k8s python client version to 20.x;
- rename "current_k8s_networking_v1beta" client to "current_k8s_networking_api_client", this will ensure that in future if networking API will have a different (e.g v2), variable name will not need a change.

addresses reanahub/reana#482
  • Loading branch information
Vladyslav Moisieienkov committed Nov 30, 2021
1 parent 3525623 commit 0435519
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions reana_commons/k8s/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# FIXME: monkeypatch to avoid `Invalid value for `names`, must not be `None``
# error when calling `current_k8s_corev1_api_client.list_node()`.
# After new Kubernetes release this should not be needed.
# After new Kubernetes release (1.22+) this should not be needed.
# https://github.com/reanahub/reana-commons/issues/197
# https://github.com/kubernetes-client/python/issues/895
# https://github.com/kubernetes/kubernetes/pull/102159
Expand All @@ -32,7 +32,7 @@ def names(self, names):
V1ContainerImage.names = V1ContainerImage.names.setter(names)


def create_api_client(api="BatchV1"):
def create_api_client(api: str = "BatchV1"):
"""Create Kubernetes API client using config.
:param api: String which represents which Kubernetes API to spawn. By
Expand All @@ -42,27 +42,27 @@ def create_api_client(api="BatchV1"):
k8s_config.load_incluster_config()
api_configuration = client.Configuration()
api_configuration.verify_ssl = False
if api == "extensions/v1beta1":
api_client = client.ExtensionsV1beta1Api()
elif api == "CoreV1":
if api == "CoreV1":
api_client = client.CoreV1Api()
elif api == "StorageV1":
api_client = client.StorageV1Api()
elif api == "AppsV1":
api_client = client.AppsV1Api()
elif api == "networking.k8s.io/v1beta1":
api_client = client.NetworkingV1beta1Api()
elif api == "networking.k8s.io/v1":
api_client = client.NetworkingV1Api()
elif api == "CustomObjectsApi":
api_client = client.CustomObjectsApi()
else:
elif api == "BatchV1":
api_client = client.BatchV1Api()
else:
raise Exception(f"Cannot create api_client of a given type: {api}")
return api_client


current_k8s_batchv1_api_client = LocalProxy(create_api_client)
current_k8s_corev1_api_client = LocalProxy(partial(create_api_client, api="CoreV1"))
current_k8s_networking_v1beta1 = LocalProxy(
partial(create_api_client, api="networking.k8s.io/v1beta1")
current_k8s_networking_api_client = LocalProxy(
partial(create_api_client, api="networking.k8s.io/v1")
)
current_k8s_storagev1_api_client = LocalProxy(
partial(create_api_client, api="StorageV1")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_snakemake_pkg(extras=""):
extras_require = {
"docs": ["Sphinx>=1.4.4", "sphinx-rtd-theme>=0.1.9",],
"tests": tests_require,
"kubernetes": ["kubernetes>=11.0.0,<12.0.0",],
"kubernetes": ["kubernetes>=20.0.0,<21.0.0",],
"yadage": ["adage==0.10.1", "yadage==0.20.1", "yadage-schemas==0.10.6",],
"snakemake": [get_snakemake_pkg()],
"snakemake_reports": [get_snakemake_pkg("[reports]")],
Expand Down

0 comments on commit 0435519

Please sign in to comment.