@@ -995,7 +995,33 @@ <R extends HasMetadata> R resourcePatch(
995995 * @see #addFinalizer(String)
996996 */
997997 public P addFinalizer () {
998- return addFinalizer (context .getControllerConfiguration ().getFinalizerName ());
998+ return addFinalizer (context .getControllerConfiguration ().getFinalizerName (), false );
999+ }
1000+
1001+ /**
1002+ * Adds the default finalizer (from controller configuration) to the primary resource. This is a
1003+ * convenience method that calls {@link #addFinalizer(String, boolean)} with the configured
1004+ * finalizer name.
1005+ *
1006+ * @param cacheOnly if {@code true} the finalizer patch does not filter its own event (see {@link
1007+ * #addFinalizer(String, boolean)})
1008+ * @return updated resource from the server response
1009+ * @see #addFinalizer(String, boolean)
1010+ */
1011+ public P addFinalizer (boolean cacheOnly ) {
1012+ return addFinalizer (context .getControllerConfiguration ().getFinalizerName (), cacheOnly );
1013+ }
1014+
1015+ /**
1016+ * Adds the given finalizer to the primary resource, filtering the own event (equivalent to {@link
1017+ * #addFinalizer(String, boolean)} with {@code cacheOnly = false}).
1018+ *
1019+ * @param finalizerName name of the finalizer to add
1020+ * @return updated resource from the server response
1021+ * @see #addFinalizer(String, boolean)
1022+ */
1023+ public P addFinalizer (String finalizerName ) {
1024+ return addFinalizer (finalizerName , false );
9991025 }
10001026
10011027 /**
@@ -1005,9 +1031,13 @@ public P addFinalizer() {
10051031 * "Trigger reconciliation on all event" mode is on.
10061032 *
10071033 * @param finalizerName name of the finalizer to add
1034+ * @param cacheOnly if {@code true} the finalizer patch only caches the response and does
1035+ * <em>not</em> filter the resulting own event, so a subsequent reconciliation is triggered by
1036+ * the finalizer addition; if {@code false} the default JSON Patch matcher is used and the own
1037+ * event is filtered
10081038 * @return updated resource from the server response
10091039 */
1010- public P addFinalizer (String finalizerName ) {
1040+ public P addFinalizer (String finalizerName , boolean cacheOnly ) {
10111041 var resource = context .getPrimaryResource ();
10121042 if (resource .isMarkedForDeletion () || resource .hasFinalizer (finalizerName )) {
10131043 return resource ;
@@ -1017,7 +1047,8 @@ public P addFinalizer(String finalizerName) {
10171047 r .addFinalizer (finalizerName );
10181048 return r ;
10191049 },
1020- r -> !r .hasFinalizer (finalizerName ));
1050+ r -> !r .hasFinalizer (finalizerName ),
1051+ cacheOnly );
10211052 }
10221053
10231054 /**
@@ -1061,6 +1092,22 @@ public P removeFinalizer(String finalizerName) {
10611092 });
10621093 }
10631094
1095+ /**
1096+ * Patches the primary resource using JSON Patch, retrying on conflict, filtering the own event
1097+ * via the default JSON Patch matcher (equivalent to {@link
1098+ * #conflictRetryingPatchPrimary(UnaryOperator, Predicate, boolean)} with {@code cacheOnly =
1099+ * false}).
1100+ *
1101+ * @param resourceChangesOperator changes to be done on the resource before update
1102+ * @param preCondition condition to check if the patch operation still needs to be performed or
1103+ * not
1104+ * @return updated resource from the server or unchanged if the precondition does not hold
1105+ */
1106+ public P conflictRetryingPatchPrimary (
1107+ UnaryOperator <P > resourceChangesOperator , Predicate <P > preCondition ) {
1108+ return conflictRetryingPatchPrimary (resourceChangesOperator , preCondition , false );
1109+ }
1110+
10641111 /**
10651112 * Patches the primary resource using JSON Patch, retrying on conflict. The {@code
10661113 * resourceChangesOperator} is applied to the current resource before each attempt; if the server
@@ -1071,12 +1118,15 @@ public P removeFinalizer(String finalizerName) {
10711118 * @param resourceChangesOperator changes to be done on the resource before update
10721119 * @param preCondition condition to check if the patch operation still needs to be performed or
10731120 * not; evaluated against the (possibly re-fetched) resource before each attempt
1121+ * @param cacheOnly if {@code true} the patch only caches the response and does <em>not</em>
1122+ * filter the resulting own event; if {@code false} the default JSON Patch matcher is used and
1123+ * the own event is filtered
10741124 * @return updated resource from the server or unchanged if the precondition does not hold
10751125 * @throws OperatorException if the maximum number of retry attempts is exceeded
10761126 */
10771127 @ SuppressWarnings ("unchecked" )
10781128 public P conflictRetryingPatchPrimary (
1079- UnaryOperator <P > resourceChangesOperator , Predicate <P > preCondition ) {
1129+ UnaryOperator <P > resourceChangesOperator , Predicate <P > preCondition , boolean cacheOnly ) {
10801130 var resource = context .getPrimaryResource ();
10811131 var client = context .getClient ();
10821132 if (log .isDebugEnabled ()) {
@@ -1088,7 +1138,12 @@ public P conflictRetryingPatchPrimary(
10881138 if (!preCondition .test (resource )) {
10891139 return resource ;
10901140 }
1091- return jsonPatchPrimary (resource , resourceChangesOperator );
1141+ return jsonPatchPrimary (
1142+ resource ,
1143+ resourceChangesOperator ,
1144+ cacheOnly
1145+ ? Options .cacheOnly ()
1146+ : Options .matchAndFilterWithDefaultMatcher (UpdateType .JSON_PATCH ));
10921147 } catch (KubernetesClientException e ) {
10931148 log .trace ("Exception during patch for resource: {}" , resource );
10941149 retryIndex ++;
0 commit comments