Skip to content

Watch CRD receives the same event #503

Description

@sebgoa

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.

Activity

  1. sebgoa commented on Apr 4, 2018

    @sebgoa
    ContributorAuthor

    so #334 does not work as is

  2. sebgoa commented on Apr 5, 2018

    @sebgoa
    ContributorAuthor

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

  3. marcellodesales commented on Apr 6, 2018

    @marcellodesales

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

  4. mbohlool commented on Apr 6, 2018

    @mbohlool
    Contributor

    @roycaihw can you take a look at this?

  5. self-assigned this
    on Apr 12, 2018
  6. roycaihw commented on Apr 26, 2018

    @roycaihw
    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

  7. marcellodesales commented on Apr 27, 2018

    @marcellodesales

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

  8. sebgoa commented on May 9, 2018

    @sebgoa
    ContributorAuthor

    confirm that the fix works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions