From 41eb66fbee95ac40d212700c1cc746ad3124ac60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 9 May 2025 09:07:08 +0200 Subject: [PATCH 1/2] improve: remove fabric8 daily build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../fabric8-next-version-schedule.yml | 30 ------- .../event/ReconciliationDispatcher.java | 79 +++++++++++++------ .../event/ReconciliationDispatcherTest.java | 7 +- 3 files changed, 60 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/fabric8-next-version-schedule.yml diff --git a/.github/workflows/fabric8-next-version-schedule.yml b/.github/workflows/fabric8-next-version-schedule.yml deleted file mode 100644 index 64d2042135..0000000000 --- a/.github/workflows/fabric8-next-version-schedule.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Fabric8 Client Snapshot Build - -env: - MAVEN_ARGS: -V -ntp -e - -concurrency: - group: ${{ github.ref }}-${{ github.workflow }} - cancel-in-progress: true -on: - schedule: - # Run on end of the day - - cron: '0 0 * * *' - workflow_dispatch: -jobs: - check_format_and_unit_tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: 'fabric8-next-version' - - name: Set up Java and Maven - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 17 - - name: Run unit tests - run: ./mvnw ${MAVEN_ARGS} clean install --file pom.xml - - build: - uses: ./.github/workflows/build.yml \ No newline at end of file diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java index c4b161ef27..c701b37fbc 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java @@ -25,6 +25,7 @@ import io.javaoperatorsdk.operator.api.reconciler.RetryInfo; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.processing.Controller; +import io.javaoperatorsdk.operator.processing.event.source.controller.ControllerEventSource; import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.*; @@ -60,7 +61,8 @@ public ReconciliationDispatcher(Controller

controller) { new CustomResourceFacade<>( controller.getCRClient(), controller.getConfiguration(), - controller.getConfiguration().getConfigurationService().getResourceCloner())); + controller.getConfiguration().getConfigurationService().getResourceCloner(), + controller.getEventSourceManager().getControllerEventSource())); } public PostExecutionControl

handleExecution(ExecutionScope

executionScope) { @@ -175,7 +177,7 @@ private PostExecutionControl

reconcileExecution( } if (updateControl.isPatchStatus()) { - customResourceFacade.patchStatus(toUpdate, originalResource); + updatedCustomResource = customResourceFacade.patchStatus(toUpdate, originalResource); } return createPostExecutionControl(updatedCustomResource, updateControl); } @@ -315,7 +317,7 @@ private P addFinalizerWithSSA(P originalResource) { objectMeta.setNamespace(originalResource.getMetadata().getNamespace()); resource.setMetadata(objectMeta); resource.addFinalizer(configuration().getFinalizerName()); - return customResourceFacade.patchResourceWithSSA(resource); + return customResourceFacade.patchResourceWithSSA(resource, originalResource); } catch (InstantiationException | IllegalAccessException | InvocationTargetException @@ -414,15 +416,30 @@ static class CustomResourceFacade { private final boolean useSSA; private final String fieldManager; private final Cloner cloner; + private final boolean previousAnnotationForDependentResourcesEventFiltering; + private final ControllerEventSource controllerEventSource; public CustomResourceFacade( MixedOperation, Resource> resourceOperation, ControllerConfiguration configuration, - Cloner cloner) { + Cloner cloner, + ControllerEventSource controllerEventSource) { this.resourceOperation = resourceOperation; this.useSSA = configuration.getConfigurationService().useSSAToPatchPrimaryResource(); this.fieldManager = configuration.fieldManager(); + this.previousAnnotationForDependentResourcesEventFiltering = + configuration + .getConfigurationService() + .previousAnnotationForDependentResourcesEventFiltering(); this.cloner = cloner; + this.controllerEventSource = controllerEventSource; + } + + private void cachePrimaryResource(R updatedResource, R previousVersionOfResource) { + if (previousAnnotationForDependentResourcesEventFiltering) { + controllerEventSource.handleRecentResourceUpdate( + ResourceID.fromResource(updatedResource), updatedResource, previousVersionOfResource); + } } public R getResource(String namespace, String name) { @@ -434,7 +451,9 @@ public R getResource(String namespace, String name) { } public R patchResourceWithoutSSA(R resource, R originalResource) { - return resource(originalResource).edit(r -> resource); + R updated = resource(originalResource).edit(r -> resource); + cachePrimaryResource(updated, originalResource); + return updated; } public R patchResource(R resource, R originalResource) { @@ -444,32 +463,43 @@ public R patchResource(R resource, R originalResource) { ResourceID.fromResource(resource), resource.getMetadata().getResourceVersion()); } + R updated; if (useSSA) { - return patchResourceWithSSA(resource); + return patchResourceWithSSA(resource, originalResource); } else { - return resource(originalResource).edit(r -> resource); + updated = resource(originalResource).edit(r -> resource); + cachePrimaryResource(updated, originalResource); + return updated; } } public R patchStatus(R resource, R originalResource) { log.trace("Patching status for resource: {} with ssa: {}", resource, useSSA); if (useSSA) { + R updated = null; var managedFields = resource.getMetadata().getManagedFields(); try { resource.getMetadata().setManagedFields(null); var res = resource(resource); - return res.subresource("status") - .patch( - new PatchContext.Builder() - .withFieldManager(fieldManager) - .withForce(true) - .withPatchType(PatchType.SERVER_SIDE_APPLY) - .build()); + updated = + res.subresource("status") + .patch( + new PatchContext.Builder() + .withFieldManager(fieldManager) + .withForce(true) + .withPatchType(PatchType.SERVER_SIDE_APPLY) + .build()); + return updated; } finally { resource.getMetadata().setManagedFields(managedFields); + if (updated != null) { + cachePrimaryResource(updated, originalResource); + } } } else { - return editStatus(resource, originalResource); + R updated = editStatus(resource, originalResource); + cachePrimaryResource(updated, originalResource); + return updated; } } @@ -490,14 +520,17 @@ private R editStatus(R resource, R originalResource) { } } - public R patchResourceWithSSA(R resource) { - return resource(resource) - .patch( - new PatchContext.Builder() - .withFieldManager(fieldManager) - .withForce(true) - .withPatchType(PatchType.SERVER_SIDE_APPLY) - .build()); + public R patchResourceWithSSA(R resource, R originalResource) { + R updated = + resource(resource) + .patch( + new PatchContext.Builder() + .withFieldManager(fieldManager) + .withForce(true) + .withPatchType(PatchType.SERVER_SIDE_APPLY) + .build()); + cachePrimaryResource(updated, originalResource); + return updated; } private Resource resource(R resource) { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java index 89f3655356..72c4db1ad9 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java @@ -144,7 +144,8 @@ void addFinalizerOnNewResource() { verify(reconciler, never()).reconcile(ArgumentMatchers.eq(testCustomResource), any()); verify(customResourceFacade, times(1)) .patchResourceWithSSA( - argThat(testCustomResource -> testCustomResource.hasFinalizer(DEFAULT_FINALIZER))); + argThat(testCustomResource -> testCustomResource.hasFinalizer(DEFAULT_FINALIZER)), + any()); } @Test @@ -357,13 +358,13 @@ void doesNotUpdateTheResourceIfNoUpdateUpdateControlIfFinalizerSet() { void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned() { removeFinalizers(testCustomResource); reconciler.reconcile = (r, c) -> UpdateControl.noUpdate(); - when(customResourceFacade.patchResourceWithSSA(any())).thenReturn(testCustomResource); + when(customResourceFacade.patchResourceWithSSA(any(), any())).thenReturn(testCustomResource); var postExecControl = reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource)); verify(customResourceFacade, times(1)) - .patchResourceWithSSA(argThat(a -> !a.getMetadata().getFinalizers().isEmpty())); + .patchResourceWithSSA(argThat(a -> !a.getMetadata().getFinalizers().isEmpty()), any()); assertThat(postExecControl.updateIsStatusPatch()).isFalse(); assertThat(postExecControl.getUpdatedCustomResource()).isPresent(); } From 80495e198208cae51dcf3e394b416f26343d9c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 9 May 2025 09:10:07 +0200 Subject: [PATCH 2/2] revert daily build removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../fabric8-next-version-schedule.yml | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/fabric8-next-version-schedule.yml diff --git a/.github/workflows/fabric8-next-version-schedule.yml b/.github/workflows/fabric8-next-version-schedule.yml new file mode 100644 index 0000000000..64d2042135 --- /dev/null +++ b/.github/workflows/fabric8-next-version-schedule.yml @@ -0,0 +1,30 @@ +name: Fabric8 Client Snapshot Build + +env: + MAVEN_ARGS: -V -ntp -e + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true +on: + schedule: + # Run on end of the day + - cron: '0 0 * * *' + workflow_dispatch: +jobs: + check_format_and_unit_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: 'fabric8-next-version' + - name: Set up Java and Maven + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + - name: Run unit tests + run: ./mvnw ${MAVEN_ARGS} clean install --file pom.xml + + build: + uses: ./.github/workflows/build.yml \ No newline at end of file