This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
Skip resumes for deleted objects, unless explicitly marked for selection #233
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prevent resource/memory leaks in some edge cases with resuming+deletion handlers.
Description
In #230, the resume handlers were fixed to be executed as regular resource-changing handlers, with multiple iterations if needed. Previously, they were executed only if they were lucky to be the first and the only in the row, and if never retried due to errors.
Problem:
This led to the resuming handlers executed even if the object was marked for deletion during the operator downtime/restart. Which, from one point of view, makes sense — since the object exists out there (only "marked" for deletion, but not actually deleted), so should be "resumed" in memory (despite it will be shut down and freed in few moments).
But, from another point of view, leads to potential memory/resource leaks, if the deletion handlers are used to free the resources and stop the tasks, and the resuming handlers allocate and start them accordingly — after they were released/stopped.
Consider an example below and a case when the operator starts and notices an object marked for deletion — should it spawn a task then?
The order of handlers is not a solution, as it can be altered at runtime due to error retries in the real cases with more logic.
Solution:
Kopf's goal is to be intuitive and human-friendly in the first place. Based on this consideration, with this PR, the resuming handlers are NOT invoked if the object is undergoing the deletion when the operator is restarted. This also matches the previous (buggy) behaviour.
However, if that is desired, a developer can declare the resume handler as deletion-compatible with
deleted=True
(see the docs in this PR), and the resuming handler will be executed even on the deletions.The main code snippet in this PR is this one:
Beside of the main change, the tests were added for the resuming decorators and handler selection. It seems, they were absent previously.
Types of Changes
Review
List of tasks the reviewer must do to review the PR