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

Error when trying to retrieve api versions #418

Closed
joeblackwaslike opened this issue Dec 14, 2017 · 3 comments
Closed

Error when trying to retrieve api versions #418

joeblackwaslike opened this issue Dec 14, 2017 · 3 comments
Labels
help-needed kind/bug Categorizes issue or PR as related to a bug.

Comments

@joeblackwaslike
Copy link

I seem to be getting a ValueError exception trying to list apis versions using client version: 4.0.0b1 on a kubernetes: 1.7.8 cluster.

I'm simply following the example in example3.py

>>> client.CoreApi().get_api_versions()
{'api_version': None,
 'kind': 'APIVersions',
 'server_address_by_client_cid_rs': [{'client_cidr': '0.0.0.0/0',
                                      'server_address': 'xxx.xxx.xxx.xxx:xxxx'}],
 'versions': ['v1']}

works fine, but the next one fails

>>> client.ApisApi().get_api_versions()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-27-6c0283bdc603> in <module>()
----> 1 client.ApisApi().get_api_versions()

~/github/telephoneorg/client-python/kubernetes/client/apis/apis_api.py in get_api_versions(self, **kwargs)
     53             return self.get_api_versions_with_http_info(**kwargs)
     54         else:
---> 55             (data) = self.get_api_versions_with_http_info(**kwargs)
     56             return data
     57

~/github/telephoneorg/client-python/kubernetes/client/apis/apis_api.py in get_api_versions_with_http_info(self, **kwargs)
    122                                         _preload_content=params.get('_preload_content', True),
    123                                         _request_timeout=params.get('_request_timeout'),
--> 124                                         collection_formats=collection_formats)

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, async, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
    319                                    body, post_params, files,
    320                                    response_type, auth_settings,
--> 321                                    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
    322         else:
    323             thread = self.pool.apply_async(self.__call_api, (resource_path, method,

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in __call_api(self, resource_path, method, path_params, query_params, header_params, body, post_params, files, response_type, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout)
    161             # deserialize response data
    162             if response_type:
--> 163                 return_data = self.deserialize(response_data, response_type)
    164             else:
    165                 return_data = None

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in deserialize(self, response, response_type)
    234             data = response.data
    235
--> 236         return self.__deserialize(data, response_type)
    237
    238     def __deserialize(self, data, klass):

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in __deserialize(self, data, klass)
    274             return self.__deserialize_datatime(data)
    275         else:
--> 276             return self.__deserialize_model(data, klass)
    277
    278     def call_api(self, resource_path, method,

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in __deserialize_model(self, data, klass)
    618                    and isinstance(data, (list, dict)):
    619                     value = data[klass.attribute_map[attr]]
--> 620                     kwargs[attr] = self.__deserialize(value, attr_type)
    621
    622         instance = klass(**kwargs)

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in __deserialize(self, data, klass)
    252                 sub_kls = re.match('list\[(.*)\]', klass).group(1)
    253                 return [self.__deserialize(sub_data, sub_kls)
--> 254                         for sub_data in data]
    255
    256             if klass.startswith('dict('):

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in <listcomp>(.0)
    252                 sub_kls = re.match('list\[(.*)\]', klass).group(1)
    253                 return [self.__deserialize(sub_data, sub_kls)
--> 254                         for sub_data in data]
    255
    256             if klass.startswith('dict('):

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in __deserialize(self, data, klass)
    274             return self.__deserialize_datatime(data)
    275         else:
--> 276             return self.__deserialize_model(data, klass)
    277
    278     def call_api(self, resource_path, method,

~/github/telephoneorg/client-python/kubernetes/client/api_client.py in __deserialize_model(self, data, klass)
    620                     kwargs[attr] = self.__deserialize(value, attr_type)
    621
--> 622         instance = klass(**kwargs)
    623
    624         if hasattr(instance, 'get_real_child_model'):

~/github/telephoneorg/client-python/kubernetes/client/models/v1_api_group.py in __init__(self, api_version, kind, name, preferred_version, server_address_by_client_cid_rs, versions)
     69         if preferred_version is not None:
     70           self.preferred_version = preferred_version
---> 71         self.server_address_by_client_cid_rs = server_address_by_client_cid_rs
     72         self.versions = versions
     73

~/github/telephoneorg/client-python/kubernetes/client/models/v1_api_group.py in server_address_by_client_cid_rs(self, server_address_by_client_cid_rs)
    187         """
    188         if server_address_by_client_cid_rs is None:
--> 189             raise ValueError("Invalid value for `server_address_by_client_cid_rs`, must not be `None`")
    190
    191         self._server_address_by_client_cid_rs = server_address_by_client_cid_rs

ValueError: Invalid value for `server_address_by_client_cid_rs`, must not be `None`

The value itself seems pretty foreign so I attempt the same kind of call using kubectl with --v=8 and check the output

I1213 20:33:31.845871   49956 loader.go:357] Config loaded from file /Users/joeblack/.kube/config
I1213 20:33:31.849207   49956 round_trippers.go:383] GET https://[snip]:6443/api
I1213 20:33:31.849241   49956 round_trippers.go:390] Request Headers:
I1213 20:33:31.849248   49956 round_trippers.go:393]     Accept: application/json, */*
I1213 20:33:31.849253   49956 round_trippers.go:393]     User-Agent: kubectl/v1.7.8 (darwin/amd64) kubernetes/bc6162c
I1213 20:33:31.982519   49956 round_trippers.go:408] Response Status: 200 OK in 133 milliseconds
I1213 20:33:31.982553   49956 round_trippers.go:411] Response Headers:
I1213 20:33:31.982560   49956 round_trippers.go:414]     Date: Thu, 14 Dec 2017 01:33:32 GMT
I1213 20:33:31.982566   49956 round_trippers.go:414]     Content-Type: application/json
I1213 20:33:31.982571   49956 round_trippers.go:414]     Content-Length: 138
I1213 20:33:31.982604   49956 request.go:991] Response Body: {"kind":"APIVersions","versions":["v1"],"serverAddressByClientCIDRs":[{"clientCIDR":"0.0.0.0/0","serverAddress":"[snip]:16443"}]}
I1213 20:33:31.983248   49956 round_trippers.go:383] GET https://[snip]:6443/apis
I1213 20:33:31.983266   49956 round_trippers.go:390] Request Headers:
I1213 20:33:31.983274   49956 round_trippers.go:393]     Accept: application/json, */*
I1213 20:33:31.983281   49956 round_trippers.go:393]     User-Agent: kubectl/v1.7.8 (darwin/amd64) kubernetes/bc6162c
I1213 20:33:31.995793   49956 round_trippers.go:408] Response Status: 200 OK in 12 milliseconds
I1213 20:33:31.995813   49956 round_trippers.go:411] Response Headers:
I1213 20:33:31.995819   49956 round_trippers.go:414]     Content-Type: application/json
I1213 20:33:31.995823   49956 round_trippers.go:414]     Content-Length: 3473
I1213 20:33:31.995828   49956 round_trippers.go:414]     Date: Thu, 14 Dec 2017 01:33:32 GMT
I1213 20:33:31.998354   49956 request.go:991] Response Body: {"kind":"APIGroupList","apiVersion":"v1","groups":[{"name":"apiregistration.k8s.io","versions":[{"groupVersion":"apiregistration.k8s.io/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"apiregistration.k8s.io/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":null},{"name":"extensions","versions":[{"groupVersion":"extensions/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"extensions/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":null},{"name":"apps","versions":[{"groupVersion":"apps/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"apps/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":null},{"name":"authentication.k8s.io","versions":[{"groupVersion":"authentication.k8s.io/v1","version":"v1"},{"groupVersion":"authentication.k8s.io/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"authentication.k8s.io/v1","version":"v1"},"serverAddressByClientCIDRs":null},{"name":"authorization.k8s.io","versions":[{"groupVersion":"authorization.k8s.io/v1","version":"v1"},{"groupVersion":"authorization.k8s.io/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"authorization.k8s.io/v1","version":"v1"},"serverAddressByClientCIDRs":null},{"name":"autoscaling","versions":[{"groupVersion":"autoscaling/v1","version":"v1"}],"preferredVersion":{"groupVersion":"autoscaling/v1","version":"v1"},"serverAddressByClientCIDRs":null},{"name":"batch","versions":[{"groupVersion":"batch/v1","version":"v1"}],"preferredVersion":{"groupVersion":"batch/v1","version":"v1"},"serverAddressByClientCIDRs":null},{"name":"certificates.k8s.io","versions":[{"groupVersion":"certificates.k8s.io/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"certificates.k8s.io/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":null},{"name":"networking.k8s.io","versions":[{"groupVersion":"networking.k8s.io/v1","version":"v1"}],"preferredVersion":{"groupVersion":"networking.k8s.io/v1","version":"v1"},"serverAddressByClientCIDRs":null},{"name":"policy","versions":[{"groupVersion":"policy/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"policy/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":null},{"name":"rbac.authorization.k8s.io","versions":[{"groupVersion":"rbac.authorization.k8s.io/v1beta1","version":"v1beta1"},{"groupVersion":"rbac.authorization.k8s.io/v1alpha1","version":"v1alpha1"}],"preferredVersion":{"groupVersion":"rbac.authorization.k8s.io/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":null},{"name":"settings.k8s.io","versions":[{"groupVersion":"settings.k8s.io/v1alpha1","version":"v1alpha1"}],"preferredVersion":{"groupVersion":"settings.k8s.io/v1alpha1","version":"v1alpha1"},"serverAddressByClientCIDRs":null},{"name":"storage.k8s.io","versions":[{"groupVersion":"storage.k8s.io/v1","version":"v1"},{"groupVersion":"storage.k8s.io/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"storage.k8s.io/v1","version":"v1"},"serverAddressByClientCIDRs":null},{"name":"apiextensions.k8s.io","versions":[{"groupVersion":"apiextensions.k8s.io/v1beta1","version":"v1beta1"}],"preferredVersion":{"groupVersion":"apiextensions.k8s.io/v1beta1","version":"v1beta1"},"serverAddressByClientCIDRs":null},{"name":"rook.io","versions":[{"groupVersion":"rook.io/v1alpha1","version":"v1alpha1"}],"preferredVersion":{"groupVersion":"rook.io/v1alpha1","version":"v1alpha1"},"serverAddressByClientCIDRs":null}]}

I'm unsure if I'm doing something drastically wrong here or whether this is a genuine bug. I assume the latter since I'm following an example provided with the client, but I'm open to being wrong as well :)

Thanks in advance!

@mbohlool mbohlool added kind/bug Categorizes issue or PR as related to a bug. help-needed labels Dec 18, 2017
@ceridwen
Copy link

This is the same underlying issue as #394. The HTTP response the server is sending contains "serverAddressByClientCIDRs":null, the new version of the client has an added check in V1APIGroup to make sure that that key is not None, and so the client crashes.

@joeblackwaslike
Copy link
Author

For anyone else experiencing this error, I was able to get expected behavior with the following monkeypatch

from kubernetes.client.models.v1_api_group import V1APIGroup


def fix_api_group_null_value():
    _server_address_by_client_cid_rs = V1APIGroup.server_address_by_client_cid_rs

    @_server_address_by_client_cid_rs.setter
    def _server_address_by_client_cid_rs(self, server_address_by_client_cid_rs):
        self._server_address_by_client_cid_rs = server_address_by_client_cid_rs

    V1APIGroup.server_address_by_client_cid_rs = _server_address_by_client_cid_rs

@roycaihw
Copy link
Member

dup of #394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-needed kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants