Index on kopf.EVERYTHING does not discard deleted objects
Long story short
index_resource function isn't called when object deleted. As a result, index is only growing constantly without any cleanup.
Kopf version
1.35.2
Kubernetes version
1.19
Python version
3.9
Code
@kopf.index(kopf.EVERYTHING)
async def all_namespaced_objects(uid, **kwargs):
if kwargs.get("namespace"):
return {(kwargs.get("namespace"), uid): True}
Logs
No response
Additional information
I fixed it using index this way. I don't know if this is a bug or not in the end.
@kopf.index(kopf.EVERYTHING, when=lambda **kwargs: kwargs.get("namespace"))
async def all_namespaced_objects(namespace, uid, **_):
return {(namespace, uid): True}
Hello. Thanks for reporting.
I tried to reproduce the issue with your code snippet, and I could not. Everything works as expected: the deleted resource disappear from the index.
Can you please describe the exact scenario which leads to leaks/non-deletions? I.e. which resource kinds and objects are not deleted from the index? How are they created/deleted, step by step?
Also, can you please elaborate on the statement:
index_resourcefunction isn't called when object deleted
What were the expectations?
To clarify: The indexing function is not supposed to be called when the resource is deleted. Instead, all index entries belonging to that object are silently discarded. No extra functions are called on this. You should be able to see that reflected in the index in all handlers happening after the deletion, including the long-running handlers (timers/daemons).
Hi,
I can't reproduce it myself now too, no idea what's going on, but I couldn't manage it to work during couple hours.
index_resource hasn't been called, because my breakpoint wasn't hit here https://github.com/nolar/kopf/blob/main/kopf/_core/engines/indexing.py#L306 when object of any kind was deleted, that's what I meant.
Please feel free to close the issue, I will add the information here if got it again.