Skip to content

Commit 41eb66f

Browse files
committed
improve: remove fabric8 daily build
I think this never worked partially because the crd generator maven plugin is not released into snapshot repo. For now I would just remove this. Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent e775349 commit 41eb66f

3 files changed

Lines changed: 60 additions & 56 deletions

File tree

.github/workflows/fabric8-next-version-schedule.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo;
2626
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
2727
import io.javaoperatorsdk.operator.processing.Controller;
28+
import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource;
2829

2930
import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.*;
3031

@@ -60,7 +61,8 @@ public ReconciliationDispatcher(Controller<P> controller) {
6061
new CustomResourceFacade<>(
6162
controller.getCRClient(),
6263
controller.getConfiguration(),
63-
controller.getConfiguration().getConfigurationService().getResourceCloner()));
64+
controller.getConfiguration().getConfigurationService().getResourceCloner(),
65+
controller.getEventSourceManager().getControllerEventSource()));
6466
}
6567

6668
public PostExecutionControl<P> handleExecution(ExecutionScope<P> executionScope) {
@@ -175,7 +177,7 @@ private PostExecutionControl<P> reconcileExecution(
175177
}
176178

177179
if (updateControl.isPatchStatus()) {
178-
customResourceFacade.patchStatus(toUpdate, originalResource);
180+
updatedCustomResource = customResourceFacade.patchStatus(toUpdate, originalResource);
179181
}
180182
return createPostExecutionControl(updatedCustomResource, updateControl);
181183
}
@@ -315,7 +317,7 @@ private P addFinalizerWithSSA(P originalResource) {
315317
objectMeta.setNamespace(originalResource.getMetadata().getNamespace());
316318
resource.setMetadata(objectMeta);
317319
resource.addFinalizer(configuration().getFinalizerName());
318-
return customResourceFacade.patchResourceWithSSA(resource);
320+
return customResourceFacade.patchResourceWithSSA(resource, originalResource);
319321
} catch (InstantiationException
320322
| IllegalAccessException
321323
| InvocationTargetException
@@ -414,15 +416,30 @@ static class CustomResourceFacade<R extends HasMetadata> {
414416
private final boolean useSSA;
415417
private final String fieldManager;
416418
private final Cloner cloner;
419+
private final boolean previousAnnotationForDependentResourcesEventFiltering;
420+
private final ControllerEventSource<R> controllerEventSource;
417421

418422
public CustomResourceFacade(
419423
MixedOperation<R, KubernetesResourceList<R>, Resource<R>> resourceOperation,
420424
ControllerConfiguration<R> configuration,
421-
Cloner cloner) {
425+
Cloner cloner,
426+
ControllerEventSource<R> controllerEventSource) {
422427
this.resourceOperation = resourceOperation;
423428
this.useSSA = configuration.getConfigurationService().useSSAToPatchPrimaryResource();
424429
this.fieldManager = configuration.fieldManager();
430+
this.previousAnnotationForDependentResourcesEventFiltering =
431+
configuration
432+
.getConfigurationService()
433+
.previousAnnotationForDependentResourcesEventFiltering();
425434
this.cloner = cloner;
435+
this.controllerEventSource = controllerEventSource;
436+
}
437+
438+
private void cachePrimaryResource(R updatedResource, R previousVersionOfResource) {
439+
if (previousAnnotationForDependentResourcesEventFiltering) {
440+
controllerEventSource.handleRecentResourceUpdate(
441+
ResourceID.fromResource(updatedResource), updatedResource, previousVersionOfResource);
442+
}
426443
}
427444

428445
public R getResource(String namespace, String name) {
@@ -434,7 +451,9 @@ public R getResource(String namespace, String name) {
434451
}
435452

436453
public R patchResourceWithoutSSA(R resource, R originalResource) {
437-
return resource(originalResource).edit(r -> resource);
454+
R updated = resource(originalResource).edit(r -> resource);
455+
cachePrimaryResource(updated, originalResource);
456+
return updated;
438457
}
439458

440459
public R patchResource(R resource, R originalResource) {
@@ -444,32 +463,43 @@ public R patchResource(R resource, R originalResource) {
444463
ResourceID.fromResource(resource),
445464
resource.getMetadata().getResourceVersion());
446465
}
466+
R updated;
447467
if (useSSA) {
448-
return patchResourceWithSSA(resource);
468+
return patchResourceWithSSA(resource, originalResource);
449469
} else {
450-
return resource(originalResource).edit(r -> resource);
470+
updated = resource(originalResource).edit(r -> resource);
471+
cachePrimaryResource(updated, originalResource);
472+
return updated;
451473
}
452474
}
453475

454476
public R patchStatus(R resource, R originalResource) {
455477
log.trace("Patching status for resource: {} with ssa: {}", resource, useSSA);
456478
if (useSSA) {
479+
R updated = null;
457480
var managedFields = resource.getMetadata().getManagedFields();
458481
try {
459482
resource.getMetadata().setManagedFields(null);
460483
var res = resource(resource);
461-
return res.subresource("status")
462-
.patch(
463-
new PatchContext.Builder()
464-
.withFieldManager(fieldManager)
465-
.withForce(true)
466-
.withPatchType(PatchType.SERVER_SIDE_APPLY)
467-
.build());
484+
updated =
485+
res.subresource("status")
486+
.patch(
487+
new PatchContext.Builder()
488+
.withFieldManager(fieldManager)
489+
.withForce(true)
490+
.withPatchType(PatchType.SERVER_SIDE_APPLY)
491+
.build());
492+
return updated;
468493
} finally {
469494
resource.getMetadata().setManagedFields(managedFields);
495+
if (updated != null) {
496+
cachePrimaryResource(updated, originalResource);
497+
}
470498
}
471499
} else {
472-
return editStatus(resource, originalResource);
500+
R updated = editStatus(resource, originalResource);
501+
cachePrimaryResource(updated, originalResource);
502+
return updated;
473503
}
474504
}
475505

@@ -490,14 +520,17 @@ private R editStatus(R resource, R originalResource) {
490520
}
491521
}
492522

493-
public R patchResourceWithSSA(R resource) {
494-
return resource(resource)
495-
.patch(
496-
new PatchContext.Builder()
497-
.withFieldManager(fieldManager)
498-
.withForce(true)
499-
.withPatchType(PatchType.SERVER_SIDE_APPLY)
500-
.build());
523+
public R patchResourceWithSSA(R resource, R originalResource) {
524+
R updated =
525+
resource(resource)
526+
.patch(
527+
new PatchContext.Builder()
528+
.withFieldManager(fieldManager)
529+
.withForce(true)
530+
.withPatchType(PatchType.SERVER_SIDE_APPLY)
531+
.build());
532+
cachePrimaryResource(updated, originalResource);
533+
return updated;
501534
}
502535

503536
private Resource<R> resource(R resource) {

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ void addFinalizerOnNewResource() {
144144
verify(reconciler, never()).reconcile(ArgumentMatchers.eq(testCustomResource), any());
145145
verify(customResourceFacade, times(1))
146146
.patchResourceWithSSA(
147-
argThat(testCustomResource -> testCustomResource.hasFinalizer(DEFAULT_FINALIZER)));
147+
argThat(testCustomResource -> testCustomResource.hasFinalizer(DEFAULT_FINALIZER)),
148+
any());
148149
}
149150

150151
@Test
@@ -357,13 +358,13 @@ void doesNotUpdateTheResourceIfNoUpdateUpdateControlIfFinalizerSet() {
357358
void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned() {
358359
removeFinalizers(testCustomResource);
359360
reconciler.reconcile = (r, c) -> UpdateControl.noUpdate();
360-
when(customResourceFacade.patchResourceWithSSA(any())).thenReturn(testCustomResource);
361+
when(customResourceFacade.patchResourceWithSSA(any(), any())).thenReturn(testCustomResource);
361362

362363
var postExecControl =
363364
reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource));
364365

365366
verify(customResourceFacade, times(1))
366-
.patchResourceWithSSA(argThat(a -> !a.getMetadata().getFinalizers().isEmpty()));
367+
.patchResourceWithSSA(argThat(a -> !a.getMetadata().getFinalizers().isEmpty()), any());
367368
assertThat(postExecControl.updateIsStatusPatch()).isFalse();
368369
assertThat(postExecControl.getUpdatedCustomResource()).isPresent();
369370
}

0 commit comments

Comments
 (0)