Skip to content

fix: resource cache after finalizer add #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ private PostExecutionControl(
this.runtimeException = runtimeException;
}

public static <R extends HasMetadata> PostExecutionControl<R> onlyFinalizerAdded() {
return new PostExecutionControl<>(true, null, false, null);
public static <R extends HasMetadata> PostExecutionControl<R> onlyFinalizerAdded(
R updatedCustomResource) {
return new PostExecutionControl<>(true, updatedCustomResource, false, null);
}

public static <R extends HasMetadata> PostExecutionControl<R> defaultDispatch() {
Expand All @@ -46,18 +47,10 @@ public static <R extends HasMetadata> PostExecutionControl<R> exceptionDuringExe
return new PostExecutionControl<>(false, null, false, exception);
}

public boolean isOnlyFinalizerHandled() {
return onlyFinalizerHandled;
}

public Optional<R> getUpdatedCustomResource() {
return Optional.ofNullable(updatedCustomResource);
}

public boolean customResourceUpdatedDuringExecution() {
return updatedCustomResource != null;
}

public boolean exceptionDuringExecution() {
return runtimeException != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ private PostExecutionControl<R> handleReconcile(
* finalizer add. This will make sure that the resources are not created before there is a
* finalizer.
*/
updateCustomResourceWithFinalizer(originalResource);
return PostExecutionControl.onlyFinalizerAdded();
var updatedResource = updateCustomResourceWithFinalizer(originalResource);
return PostExecutionControl.onlyFinalizerAdded(updatedResource);
} else {
var resourceForExecution =
cloneResource(originalResource);
Expand Down Expand Up @@ -295,11 +295,11 @@ private PostExecutionControl<R> handleCleanup(R resource, Context<R> context) {
return postExecutionControl;
}

private void updateCustomResourceWithFinalizer(R resource) {
private R updateCustomResourceWithFinalizer(R resource) {
log.debug(
"Adding finalizer for resource: {} version: {}", getUID(resource), getVersion(resource));
resource.addFinalizer(configuration().getFinalizerName());
customResourceFacade.replaceResourceWithLock(resource);
return customResourceFacade.replaceResourceWithLock(resource);
}

private R updateCustomResource(R resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,16 @@ void doesNotUpdateTheResourceIfNoUpdateUpdateControlIfFinalizerSet() {
@Test
void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned() {
removeFinalizers(testCustomResource);

reconciler.reconcile = (r, c) -> UpdateControl.noUpdate();
when(customResourceFacade.replaceResourceWithLock(any())).thenReturn(testCustomResource);

reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource));
var postExecControl =
reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource));

assertEquals(1, testCustomResource.getMetadata().getFinalizers().size());
verify(customResourceFacade, times(1)).replaceResourceWithLock(any());
assertThat(postExecControl.updateIsStatusPatch()).isFalse();
assertThat(postExecControl.getUpdatedCustomResource()).isPresent();
}

@Test
Expand Down