Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0 client] kubernetes.client.apis.apps_v1beta1_api.AppsV1beta1Api.get_api_resources() crashes on OpenShift 3.6 #139

Closed
ceridwen opened this issue Jan 16, 2018 · 6 comments

Comments

@ceridwen
Copy link
Contributor

This is a backwards-compatibility issue.

  File "/Users/user/test_automation/test_automation/kubernetes_.py", line 55, in get_resource_info
    api_group = api.get_api_resources()
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/apis/apps_v1beta1_api.py", line 1264, in get_api_resources
    (data) = self.get_api_resources_with_http_info(**kwargs)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/apis/apps_v1beta1_api.py", line 1333, in get_api_resources_with_http_info
    collection_formats=collection_formats)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 321, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 163, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 236, in deserialize
    return self.__deserialize(data, response_type)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 620, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 254, in __deserialize
    for sub_data in data]
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 254, in <listcomp>
    for sub_data in data]
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
    instance = klass(**kwargs)
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/models/v1_api_resource.py", line 82, in __init__
    self.singular_name = singular_name
  File "/Users/user/virtualenvs/client4.0/lib/python3.6/site-packages/kubernetes/client/models/v1_api_resource.py", line 252, in singular_name
    raise ValueError("Invalid value for `singular_name`, must not be `None`")

In the 4.0 client, there's a bunch of additional validation code added to ensure that required fields can't be null/None. Unfortunately, the Kubernetes API server will still return null/None values for some of these fields even though they're supposedly required. I have a slightly more detailed explanation of a similar bug here: kubernetes-client/python#394 . (It's closed but the issue is not fixed.) I don't know if this is a bug in the OpenShift 3.6 API server (it's returning null for a required field) or the OpenAPI spec (the field shouldn't be required).

@dlbewley
Copy link

I believe I'm also hitting this like this on my 3.6 cluster with openshift==0.4.1.

# roughly...
from openshift import config as oconfig, client as oclient
project.oapi = oclient.OapiApi()
project.oapi.list_namespaced_role_binding(project.name)
# results in
Invalid value for `api_group`, must not be `None`

Any tips to work around, or just downgrade releases and wait?

@dlbewley
Copy link

FWIW same issue with:

  • kubernetes==5.0.0
  • openshift==0.5.0a1

@ceridwen
Copy link
Contributor Author

I'm currently using this monkey-patch to work around a similar issue in Kubernetes:
kubernetes-client/python#418 (comment)

I haven't bothered to put together a monkey-patch to fix this problem. If you do, please post it here?

I wouldn't hold my breath waiting for this bug to be fixed. I filed it upstream three months ago when the 4.0 client was in beta, they closed my bug even though it was still there, and no one's paid any attention to it since despite the steadily-accumulating list of issues that can be traced to the same cause.

@dlbewley
Copy link

Thanks for the commiseration. To be most explicit this is what I'm seeing with kubernetes==4.0.0
& openshift==0.4.1, but I'm not quite sure how to tackle writing a monkey-patch around the missing value.

Traceback (most recent call last):
  File "/Users/dlbewley/src/openshift/openshift-tools/project-report.py", line 63, in <module>
    ProjectReport()
  File "/Users/dlbewley/src/openshift/openshift-tools/project-report.py", line 34, in __init__
    roles = project.oapi.list_namespaced_role_binding(project.name)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/openshift/client/apis/oapi_api.py", line 16430, in list_namespaced_role_binding
    (data) = self.list_namespaced_role_binding_with_http_info(namespace, **kwargs)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/openshift/client/apis/oapi_api.py", line 16533, in list_namespaced_role_binding_with_http_info
    collection_formats=collection_formats)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 321, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 163, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 236, in deserialize
    return self.__deserialize(data, response_type)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/openshift/client/api_client.py", line 11, in _ApiClient__deserialize
    return super(ApiClient, self).__deserialize(data, klass)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 620, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/openshift/client/api_client.py", line 11, in _ApiClient__deserialize
    return super(ApiClient, self).__deserialize(data, klass)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 254, in __deserialize
    for sub_data in data]
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 254, in <listcomp>
    for sub_data in data]
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/openshift/client/api_client.py", line 11, in _ApiClient__deserialize
    return super(ApiClient, self).__deserialize(data, klass)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 620, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/openshift/client/api_client.py", line 11, in _ApiClient__deserialize
    return super(ApiClient, self).__deserialize(data, klass)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
    instance = klass(**kwargs)
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/models/v1_role_ref.py", line 55, in __init__
    self.api_group = api_group
  File "/Users/dlbewley/src/openshift/openshift-tools/pyenv/lib/python3.6/site-packages/kubernetes/client/models/v1_role_ref.py", line 80, in api_group
    raise ValueError("Invalid value for `api_group`, must not be `None`")
ValueError: Invalid value for `api_group`, must not be `None`

@dlbewley
Copy link

Same behavior after openshift upgrade:

  • OpenShift v3.7.23
  • openshift==0.4.3
  • kubernetes==4.0.0

With only a marginal understanding, I have produced this monkey patch which has gotten me past the above and a subsequent ValueError:

# API server is returning invalid values according to the demands
# of the swagger generated API client. This monkeypatch works
# around the bugs I have run into so far.
#
# Related issues:
# - https://github.com/kubernetes-client/python/issues/415
# - https://github.com/openshift/openshift-restclient-python/issues/139
# - https://github.com/kubernetes-client/python/issues/418
# - https://github.com/kubernetes-client/python/issues/394

# tripped by openshift.client.OapiApi.list_namespaced_role_binding()
from kubernetes.client.models.v1_role_ref import V1RoleRef

@property
def kind(self):
    return self._kind

@kind.setter
def kind(self, kind):
    if kind is None:
        kind = ''
    self._kind = kind

@property
def api_group(self):
    return self._api_group

@api_group.setter
def api_group(self, api_group):
    if api_group is None:
        api_group = ''
    self._api_group = api_group

V1RoleRef.kind = kind
V1RoleRef.api_group = api_group 

@fabianvf
Copy link
Member

Unfortunately if the error is coming from the kubernetes client we don't have any control of how they handle validation. You'll have to refile the issue against github.com/kubernetes-client/python. I've seen this and attempted to fix/workaround it on a few of the openshift models (still haven't found a good root cause/fix yet though). I'm sorry you're still seeing this after so long, I'll see if I can get the kubernetes-client maintainers' attention. If you do refile, please ping me on the issue and I can bump it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants