Client-go: Get deleted object from work queue

Created on 20 Sep 2017  路  3Comments  路  Source: kubernetes/client-go

We are in the process of using workqueue for our various controllers. One of the issue I see is that dequeue from workqueue does not return the object (it is nil). I understand the idea that the desired state by user is nil, after an object is deleted. But there are cases where we need access to the metadata/spec on the object. One work around I have found is to register my controller as a finalizer so I can get the object in the UpdateFunc(). One issue with finalizers is that someone can remove them by mistake. Can WorkQueue return deleted objects?

https://github.com/kubernetes/client-go/blob/c6f8cf2c47d21d55fa0df928291b2580544886c8/examples/workqueue/main.go#L69-L88

Most helpful comment

Thank @liggitt @munnerz . I have used a separate indexer to keep track of deleted items. Here is what my modification looks like https://github.com/tamalsaha/workqueue-demo/pull/1/files . If you have any comments, please let me know in the pr.

All 3 comments

I'm also waiting for the answer!

The queue just stores the key (typically namespace/name) of the object that changed in a way that needs to be processed. The workqueue should take the absence of the object in the store/indexer to mean the object doesn't exist and should be removed.

If you need the object, hook in at the DeleteFunc level to temporarily store the deleted object for use but be aware it is not always available (if your watch drops and gets reestablished right at deletion time you might not have the final version of the object available, or if your controller is down while an object is created and then deleted, you won't ever know it existed)

Thank @liggitt @munnerz . I have used a separate indexer to keep track of deleted items. Here is what my modification looks like https://github.com/tamalsaha/workqueue-demo/pull/1/files . If you have any comments, please let me know in the pr.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yashbhutwala picture yashbhutwala  路  4Comments

h0tbird picture h0tbird  路  3Comments

antoineco picture antoineco  路  6Comments

narasago picture narasago  路  3Comments

mheese picture mheese  路  5Comments