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

Watch CRD receives the same event #503

Closed
sebgoa opened this issue Apr 4, 2018 · 7 comments · Fixed by kubernetes-client/python-base#64
Closed

Watch CRD receives the same event #503

sebgoa opened this issue Apr 4, 2018 · 7 comments · Fixed by kubernetes-client/python-base#64
Assignees

Comments

@sebgoa
Copy link
Contributor

sebgoa commented Apr 4, 2018

It seems that when watching CRD custom objects we keep receiving the same event.

here is how to reproduce, kubectl create -f the following CRD.

kind: CustomResourceDefinition
metadata:
  name: foobars.yoyo.com
spec:
  group: yoyo.com
  names:
    kind: foobar
    listKind: foobarList
    plural: foobars
    singular: foobar
  scope: Namespaced
  version: v1beta1

Then run this watch script:

from kubernetes import client, config, watch

GROUP = "yoyo.com"
VERSION = "v1beta1"
PLURAL = "foobars"

config.load_kube_config()

crds = client.CustomObjectsApi()
        
resource_version = ""

while True:

    print "initializing stream"
    stream = watch.Watch().stream(crds.list_cluster_custom_object,
                                  GROUP, VERSION, PLURAL,
                                  resource_version=resource_version)
    for event in stream:
        t = event["type"]
        obj = event["object"]
    
        print t
        print obj  

        # Configure where to resume streaming.
        metadata = obj['metadata']

        if metadata['resourceVersion'] is not None:
            resource_version = metadata['resourceVersion']
            print resource_version

and create a custom object like so:

apiVersion: yoyo.com/v1beta1
kind: foobar
metadata:
  name: test
spec:
  whatever: youwant

The script stdout will be:

$ python ./bibi.py 
initializing stream
ADDED
{u'kind': u'foobar', u'spec': {}, u'apiVersion': u'yoyo.com/v1beta1', u'metadata': {u'name': u'test', u'clusterName': u'', u'namespace': u'default', u'resourceVersion': u'84148', u'creationTimestamp': u'2018-04-04T14:07:40Z', u'selfLink': u'/apis/yoyo.com/v1beta1/namespaces/default/foobars/test', u'uid': u'89a26340-3811-11e8-816b-0800272f923d'}}
84148
ADDED
{u'kind': u'foobar', u'spec': {}, u'apiVersion': u'yoyo.com/v1beta1', u'metadata': {u'name': u'test', u'clusterName': u'', u'namespace': u'default', u'resourceVersion': u'84148', u'creationTimestamp': u'2018-04-04T14:07:40Z', u'selfLink': u'/apis/yoyo.com/v1beta1/namespaces/default/foobars/test', u'uid': u'89a26340-3811-11e8-816b-0800272f923d'}}
84148
ADDED

The stream does not die so the resource version never gets reset. The for loop keeps getting the same event over and over.

I was expecting the event to be received only once.

@sebgoa
Copy link
Contributor Author

sebgoa commented Apr 4, 2018

so #334 does not work as is

@sebgoa
Copy link
Contributor Author

sebgoa commented Apr 5, 2018

@mbohlool Do you know who can have a look at this ? I am struggling to figure it out.

@marcellodesales
Copy link

@sebgoa I actually have seen the same exact thing... I'm looking at the status and discarding if it has been populated...

@mbohlool
Copy link
Contributor

mbohlool commented Apr 6, 2018

@roycaihw can you take a look at this?

@roycaihw roycaihw self-assigned this Apr 12, 2018
@roycaihw
Copy link
Member

The problem seems to be watch deserializing a CR json response into a dict instead of an object of a class, because we don't have model defined for CR, and hasattr() doesn't work for dict. As a result watch failed to update resource_version from last response. I will send a PR to fix this

@marcellodesales
Copy link

@roycaihw That would be awesome to have this merged... Thanks a lot for finding the solution...

@sebgoa
Copy link
Contributor Author

sebgoa commented May 9, 2018

confirm that the fix works.

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

Successfully merging a pull request may close this issue.

4 participants