Skip to content

Commit 0352415

Browse files
authored
docs: better explain noFinalizerRemoval use case (#1790)
1 parent 1dd9930 commit 0352415

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public interface Cleaner<P extends HasMetadata> {
66

77
/**
88
* This method turns on automatic finalizer usage.
9-
*
9+
* <p>
1010
* The implementation should delete the associated component(s). This method is called when an
1111
* object is marked for deletion. After it's executed the custom resource finalizer is
1212
* automatically removed by the framework; unless the return value is
@@ -21,9 +21,11 @@ public interface Cleaner<P extends HasMetadata> {
2121
* @param resource the resource that is marked for deletion
2222
* @param context the context with which the operation is executed
2323
* @return {@link DeleteControl#defaultDelete()} - so the finalizer is automatically removed after
24-
* the call. {@link DeleteControl#noFinalizerRemoval()} if you don't want to remove the
25-
* finalizer to indicate that the resource should not be deleted after all, in which case
26-
* the controller should restore the resource's state appropriately.
24+
* the call. Use {@link DeleteControl#noFinalizerRemoval()} when you don't want to remove
25+
* the finalizer immediately but rather wait asynchronously until all secondary resources
26+
* are deleted, thus allowing you to keep the primary resource around until you are sure
27+
* that it can be safely deleted.
28+
* @see DeleteControl#noFinalizerRemoval()
2729
*/
2830
DeleteControl cleanup(P resource, Context<P> context);
2931

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DeleteControl.java

+15
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@ private DeleteControl(boolean removeFinalizer) {
88
this.removeFinalizer = removeFinalizer;
99
}
1010

11+
/**
12+
* @return delete control that will remove finalizer.
13+
*/
1114
public static DeleteControl defaultDelete() {
1215
return new DeleteControl(true);
1316
}
1417

18+
/**
19+
* In some corner cases it might take some time for secondary resources to be cleaned up. In such
20+
* situation, the reconciler shouldn't remove the finalizer until it is safe for the primary
21+
* resource to be deleted (because, e.g., secondary resources being removed might need its
22+
* information to proceed correctly). Using this method will instruct the reconciler to leave the
23+
* finalizer in place, presumably to wait for a new reconciliation triggered by event sources on
24+
* the secondary resources (e.g. when they are effectively deleted/cleaned-up) to check whether it
25+
* is now safe to delete the primary resource and therefore, remove its finalizer by returning
26+
* {@link #defaultDelete()} then.
27+
*
28+
* @return delete control that will not remove finalizer.
29+
*/
1530
public static DeleteControl noFinalizerRemoval() {
1631
return new DeleteControl(false);
1732
}

0 commit comments

Comments
 (0)