Skip to content

Watch CRD receives the same event #503

@sebgoa

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions