2323
2424import io .fabric8 .kubernetes .api .model .HasMetadata ;
2525import io .fabric8 .kubernetes .api .model .KubernetesResourceList ;
26- import io .fabric8 .kubernetes .api .model .Namespaced ;
2726import io .fabric8 .kubernetes .client .KubernetesClientException ;
2827import io .fabric8 .kubernetes .client .dsl .MixedOperation ;
2928import io .fabric8 .kubernetes .client .dsl .Resource ;
@@ -188,7 +187,8 @@ private PostExecutionControl<P> reconcileExecution(
188187 }
189188
190189 if (updateControl .isPatchResource ()) {
191- updatedCustomResource = patchResource (context , toUpdate , originalResource );
190+ updatedCustomResource =
191+ patchResource (context , toUpdate , originalResource , updateControl .isFilterPatchEvent ());
192192 if (!useSSA ) {
193193 toUpdate
194194 .getMetadata ()
@@ -197,7 +197,8 @@ private PostExecutionControl<P> reconcileExecution(
197197 }
198198
199199 if (updateControl .isPatchStatus ()) {
200- customResourceFacade .patchStatus (context , toUpdate , originalResource );
200+ customResourceFacade .patchStatus (
201+ context , toUpdate , originalResource , updateControl .isFilterPatchEvent ());
201202 }
202203 return createPostExecutionControl (updatedCustomResource , updateControl , executionScope );
203204 }
@@ -235,7 +236,10 @@ public boolean isLastAttempt() {
235236 try {
236237 updatedResource =
237238 customResourceFacade .patchStatus (
238- context , errorStatusUpdateControl .getResource ().orElseThrow (), originalResource );
239+ context ,
240+ errorStatusUpdateControl .getResource ().orElseThrow (),
241+ originalResource ,
242+ errorStatusUpdateControl .isFilterPatchEvent ());
239243 } catch (Exception ex ) {
240244 int code = ex instanceof KubernetesClientException kcex ? kcex .getCode () : -1 ;
241245 Level exceptionLevel = Level .ERROR ;
@@ -341,7 +345,7 @@ private PostExecutionControl<P> handleCleanup(
341345 return postExecutionControl ;
342346 }
343347
344- private P patchResource (Context <P > context , P resource , P originalResource ) {
348+ private P patchResource (Context <P > context , P resource , P originalResource , boolean filterEvent ) {
345349 log .debug (
346350 "Updating resource: {} with version: {}; SSA: {}" ,
347351 getUID (resource ),
@@ -354,7 +358,7 @@ private P patchResource(Context<P> context, P resource, P originalResource) {
354358 // addFinalizer already prevents adding an already present finalizer so no need to check
355359 resource .addFinalizer (finalizerName );
356360 }
357- return customResourceFacade .patchResource (context , resource , originalResource );
361+ return customResourceFacade .patchResource (context , resource , originalResource , filterEvent );
358362 }
359363
360364 ControllerConfiguration <P > configuration () {
@@ -394,40 +398,38 @@ public R getResource(String namespace, String name) {
394398 }
395399 }
396400
397- public R patchResourceWithoutSSA (R resource , R originalResource ) {
398- return resource (originalResource ).edit (r -> resource );
399- }
400-
401- public R patchResource (Context <R > context , R resource , R originalResource ) {
401+ public R patchResource (
402+ Context <R > context , R resource , R originalResource , boolean filterEvent ) {
402403 if (log .isDebugEnabled ()) {
403404 log .debug (
404405 "Trying to replace resource {}, version: {}" ,
405406 ResourceID .fromResource (resource ),
406407 resource .getMetadata ().getResourceVersion ());
407408 }
408409 if (useSSA ) {
409- return ReconcileUtils .serverSideApplyPrimary (context , resource );
410+ return ReconcileUtils .serverSideApplyPrimary (context , resource , filterEvent );
410411 } else {
411- return ReconcileUtils .jsonPatchPrimary (context , originalResource , r -> resource );
412+ return ReconcileUtils .jsonPatchPrimary (
413+ context , originalResource , r -> resource , filterEvent );
412414 }
413415 }
414416
415- public R patchStatus (Context <R > context , R resource , R originalResource ) {
417+ public R patchStatus (Context <R > context , R resource , R originalResource , boolean filterEvent ) {
416418 log .trace ("Patching status for resource: {} with ssa: {}" , resource , useSSA );
417419 if (useSSA ) {
418420 var managedFields = resource .getMetadata ().getManagedFields ();
419421 try {
420422 resource .getMetadata ().setManagedFields (null );
421- return ReconcileUtils .serverSideApplyPrimaryStatus (context , resource );
423+ return ReconcileUtils .serverSideApplyPrimaryStatus (context , resource , filterEvent );
422424 } finally {
423425 resource .getMetadata ().setManagedFields (managedFields );
424426 }
425427 } else {
426- return editStatus (context , resource , originalResource );
428+ return editStatus (context , resource , originalResource , filterEvent );
427429 }
428430 }
429431
430- private R editStatus (Context <R > context , R resource , R originalResource ) {
432+ private R editStatus (Context <R > context , R resource , R originalResource , boolean filterEvent ) {
431433 String resourceVersion = resource .getMetadata ().getResourceVersion ();
432434 // the cached resource should not be changed in any circumstances
433435 // that can lead to all kinds of race conditions.
@@ -441,19 +443,14 @@ private R editStatus(Context<R> context, R resource, R originalResource) {
441443 r -> {
442444 ReconcilerUtilsInternal .setStatus (r , ReconcilerUtilsInternal .getStatus (resource ));
443445 return r ;
444- });
446+ },
447+ filterEvent );
445448 } finally {
446449 // restore initial resource version
447450 clonedOriginal .getMetadata ().setResourceVersion (resourceVersion );
448451 resource .getMetadata ().setResourceVersion (resourceVersion );
449452 }
450453 }
451-
452- private Resource <R > resource (R resource ) {
453- return resource instanceof Namespaced
454- ? resourceOperation .inNamespace (resource .getMetadata ().getNamespace ()).resource (resource )
455- : resourceOperation .resource (resource );
456- }
457454 }
458455
459456 private boolean triggerOnAllEvents () {
0 commit comments