1
1
package io .javaoperatorsdk .operator .processing .event ;
2
2
3
- import java .util .function .Function ;
4
-
5
3
import org .slf4j .Logger ;
6
4
import org .slf4j .LoggerFactory ;
7
5
36
34
*/
37
35
class ReconciliationDispatcher <P extends HasMetadata > {
38
36
39
- public static final int MAX_FINALIZER_REMOVAL_RETRY = 10 ;
37
+ public static final int MAX_UPDATE_RETRY = 10 ;
40
38
41
39
private static final Logger log = LoggerFactory .getLogger (ReconciliationDispatcher .class );
42
40
@@ -295,8 +293,8 @@ private PostExecutionControl<P> handleCleanup(P originalResource, P resource,
295
293
// cleanup is finished, nothing left to done
296
294
final var finalizerName = configuration ().getFinalizerName ();
297
295
if (deleteControl .isRemoveFinalizer () && resource .hasFinalizer (finalizerName )) {
298
- P customResource = conflictRetryingPatch ( resource , originalResource ,
299
- r -> r . removeFinalizer ( finalizerName ) );
296
+ resource . removeFinalizer ( finalizerName );
297
+ P customResource = conflictRetryingUpdate ( resource );
300
298
return PostExecutionControl .customResourceFinalizerRemoved (customResource );
301
299
}
302
300
}
@@ -315,9 +313,8 @@ private P updateCustomResourceWithFinalizer(P resourceForExecution, P originalRe
315
313
log .debug (
316
314
"Adding finalizer for resource: {} version: {}" , getUID (originalResource ),
317
315
getVersion (originalResource ));
318
-
319
- return conflictRetryingPatch (resourceForExecution , originalResource ,
320
- r -> r .addFinalizer (configuration ().getFinalizerName ()));
316
+ resourceForExecution .addFinalizer (configuration ().getFinalizerName ());
317
+ return conflictRetryingUpdate (resourceForExecution );
321
318
}
322
319
323
320
private P updateCustomResource (P resource ) {
@@ -330,29 +327,24 @@ ControllerConfiguration<P> configuration() {
330
327
return controller .getConfiguration ();
331
328
}
332
329
333
- public P conflictRetryingPatch (P resource , P originalResource ,
334
- Function <P , Boolean > modificationFunction ) {
330
+ public P conflictRetryingUpdate (P resource ) {
335
331
if (log .isDebugEnabled ()) {
336
332
log .debug ("Removing finalizer on resource: {}" , ResourceID .fromResource (resource ));
337
333
}
338
334
int retryIndex = 0 ;
339
335
while (true ) {
340
336
try {
341
- var modified = modificationFunction .apply (resource );
342
- if (Boolean .FALSE .equals (modified )) {
343
- return resource ;
344
- }
345
- return customResourceFacade .serverSideApplyLockResource (resource , originalResource );
337
+ return customResourceFacade .updateResource (resource );
346
338
} catch (KubernetesClientException e ) {
347
339
log .trace ("Exception during patch for resource: {}" , resource );
348
340
retryIndex ++;
349
341
// only retry on conflict (HTTP 409), otherwise fail
350
342
if (e .getCode () != 409 ) {
351
343
throw e ;
352
344
}
353
- if (retryIndex >= MAX_FINALIZER_REMOVAL_RETRY ) {
345
+ if (retryIndex >= MAX_UPDATE_RETRY ) {
354
346
throw new OperatorException (
355
- "Exceeded maximum (" + MAX_FINALIZER_REMOVAL_RETRY
347
+ "Exceeded maximum (" + MAX_UPDATE_RETRY
356
348
+ ") retry attempts to patch resource: "
357
349
+ ResourceID .fromResource (resource ));
358
350
}
0 commit comments