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

Compatibility issue between K8s v1.9 and python client v5.0 #484

Closed
huang195 opened this issue Mar 13, 2018 · 2 comments
Closed

Compatibility issue between K8s v1.9 and python client v5.0 #484

huang195 opened this issue Mar 13, 2018 · 2 comments

Comments

@huang195
Copy link

I used kubeadm to install a k8s cluster:

root@haih2:~# kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"d2835416544f298c919e2ead3be3d0864b52323b", GitTreeState:"clean", BuildDate:"2018-02-07T12:22:21Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"d2835416544f298c919e2ead3be3d0864b52323b", GitTreeState:"clean", BuildDate:"2018-02-07T11:55:20Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}

I used pip to install kubernetes python client version 5.0.

root@haih2:~# pip show kubernetes
---
Metadata-Version: 2.0
Name: kubernetes
Version: 5.0.0
Summary: Kubernetes python client
Home-page: https://github.com/kubernetes-client/python
Author: Kubernetes
Author-email: UNKNOWN
Installer: pip
License: Apache License Version 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: ipaddress, six, requests-oauthlib, pyyaml, python-dateutil, certifi, websocket-client, google-auth, setuptools, urllib3, requests
Classifiers:
  Development Status :: 5 - Production/Stable
  Topic :: Utilities
  Intended Audience :: Developers
  Intended Audience :: Information Technology
  License :: OSI Approved :: Apache Software License
  Operating System :: OS Independent
  Programming Language :: Python
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Programming Language :: Python :: 3.4
  Programming Language :: Python :: 3.5
  Programming Language :: Python :: 3.6

Per README, K8s python client v5.0 is compatible with K8s v1.9, but a simple program like the following doesn't work:

from kubernetes import client, config, watch
import sys

config.load_kube_config(config_file='./config')
a = client.CoreV1Api()
w = watch.Watch()
for event in w.stream(a.list_event_for_all_namespaces, resource_version=1):
    print (event)

The error message I got is:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    for event in w.stream(a.list_event_for_all_namespaces, resource_version=1):
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/watch/watch.py", line 127, in stream
    yield self.unmarshal_event(line, return_type)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/watch/watch.py", line 86, in unmarshal_event
    js['object'] = self._api_client.deserialize(obj, return_type)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 239, in deserialize
    return self.__deserialize(data, response_type)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 279, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 625, in __deserialize_model
    instance = klass(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/models/v1_event.py", line 107, in __init__
    self.involved_object = involved_object
  File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/models/v1_event.py", line 266, in involved_object
    raise ValueError("Invalid value for `involved_object`, must not be `None`")
ValueError: Invalid value for `involved_object`, must not be `None`
@howardshaw
Copy link

I encount the same issue with you in k8s 1.9.3.

>>> for event in w.stream(a.list_event_for_all_namespaces, resource_version=1):
...   print (event)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/kubernetes/watch/watch.py", line 125, in stream
    yield self.unmarshal_event(line, return_type)
  File "/usr/lib/python3.6/site-packages/kubernetes/watch/watch.py", line 84, in unmarshal_event
    js['object'] = self._api_client.deserialize(obj, return_type)
  File "/usr/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 236, in deserialize
    return self.__deserialize(data, response_type)
  File "/usr/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
    instance = klass(**kwargs)
  File "/usr/lib/python3.6/site-packages/kubernetes/client/models/v1_event.py", line 107, in __init__
    self.involved_object = involved_object
  File "/usr/lib/python3.6/site-packages/kubernetes/client/models/v1_event.py", line 266, in involved_object
    raise ValueError("Invalid value for `involved_object`, must not be `None`")
ValueError: Invalid value for `involved_object`, must not be `None

pip info as below

# pip3 show kubernetes
Name: kubernetes
Version: 5.0.0
Summary: Kubernetes python client
Home-page: https://github.com/kubernetes-client/python
Author: Kubernetes
Author-email: UNKNOWN
License: Apache License Version 2.0
Location: /usr/lib/python3.6/site-packages
Requires: google-auth, python-dateutil, certifi, ipaddress, setuptools, websocket-client, urllib3, requests-oauthlib, six, requests, pyyaml

@roycaihw
Copy link
Member

The problem is that API server returns 410 when the resource version is too old (resource_version=1):

{"type":"ERROR","object":{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"The resourceVersion for the provided watch is too old.","reason":"Expired","code":410}}

And the python client code tries to validate the error object as an event object, and reports a validation error. I would suggest that when API server responds with an error, we should raise it before parsing it into a regular API object.

If you modify the parameter to be resource_version=0 (return what we currently have in cache) or remove the parameter (defaults to changes from the beginning of history) it will work.

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