openshift/openshift-restclient-python

get_resources_for_api_version() expects sub-resource names to be of the format a/b

dbasunag opened this issue · 5 comments

get_resources_for_api_version() in https://github.com/openshift/openshift-restclient-python/blob/master/openshift/dynamic/discovery.py#L133, currently expects sub-resource names to be of the format a/b. This does not work with newly added apis in kubevirt which are of the format a/b/c. https://github.com/kubevirt/kubevirt/blame/9cf6dbb3e33c9ec9e9af8b18eb115c7fb9f7c311/pkg/virt-operator/resource/generate/rbac/cluster.go#L45-49

{noformat}
12:15:59 INTERNALERROR> File ".....//.venv/lib/python3.9/site-packages/kubernetes/dynamic/discovery.py", line 269, in __search
12:15:59 INTERNALERROR> resourcePart.resources = self.get_resources_for_api_version(
12:15:59 INTERNALERROR> File "...../.venv/lib/python3.9/site-packages/openshift/dynamic/discovery.py", line 133, in get_resources_for_api_version
12:15:59 INTERNALERROR> resource, name = subresource['name'].split('/')
12:15:59 INTERNALERROR> ValueError: too many values to unpack (expected 2)
{noformat}

Are the sub-resource names supposed to be restricted to this a/b format because of any kubernetes or openshift restrictions? Any help would be highly appreciated.

@fabianvf can you please help? I do see the same restrictions on https://github.com/kubernetes-client/python/blob/master/kubernetes/base/dynamic/discovery.py#L173, but I am trying to understand where this limitation is coming from.

@dbasunag I think it's probably just a bug/oversight, since I don't know of any other subresources that include a /. Active development of the dynamic client has moved here https://github.com/kubernetes-client/python , this library just inherits from it now. I think the fix should be pretty straightforward though, should just be able to change resource, name = subresource['name'].split('/') to resource, name = subresource['name'].split('/', 1). I can put up a PR or review/approve one if you'd like to

Thanks @fabianvf. I will create a PR and let you know.