Skip to content

improve: delete GC dependent if reconcile precondition not met #1871

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 4 commits into from
Apr 26, 2023
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 @@ -149,7 +149,10 @@ protected void doRun(DependentResourceNode<R, P> dependentResourceNode,
DependentResource<R, P> dependentResource) {
var deletePostCondition = dependentResourceNode.getDeletePostcondition();

if (dependentResource.isDeletable()) {
// GarbageCollected status is irrelevant here, as this method is only called when a
// precondition does not hold,
// a deleter should be deleted even if it is otherwise garbage collected
if (dependentResource instanceof Deleter) {
((Deleter<P>) dependentResource).delete(primary, context);
}
boolean deletePostConditionMet = isConditionMet(deletePostCondition, dependentResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AbstractWorkflowExecutorTest {
protected TestDeleterDependent drDeleter = new TestDeleterDependent("DR_DELETER");
protected TestErrorDependent drError = new TestErrorDependent("ERROR_1");
protected TestErrorDeleterDependent errorDD = new TestErrorDeleterDependent("ERROR_DELETER");
protected GarbageCollectedDeleter gcDeleter = new GarbageCollectedDeleter("GC_DELETER");

@SuppressWarnings("rawtypes")
protected final Condition noMetDeletePostCondition = (primary, secondary, context) -> false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,14 @@ void cleanupConditionDiamondWorkflow() {

@Test
void dontDeleteIfGarbageCollected() {
GarbageCollectedDeleter gcDel = new GarbageCollectedDeleter("GC_DELETER");
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(gcDel)
.addDependentResource(gcDeleter)
.build();

var res = workflow.cleanup(new TestCustomResource(), null);

assertThat(executionHistory)
.notReconciled(gcDel);
.notReconciled(gcDeleter);

Assertions.assertThat(res.getDeleteCalledOnDependents()).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,29 @@ void diamondShareWithReadyCondition() {
Assertions.assertThat(res.getNotReadyDependents()).containsExactlyInAnyOrder(dr2);
}

@Test
void garbageCollectedResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(gcDeleter).withReconcilePrecondition(not_met_reconcile_condition)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);

Assertions.assertThat(res.getErroredDependents()).isEmpty();
assertThat(executionHistory).deleted(gcDeleter);
}

@Test
void garbageCollectedDeepResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(dr1).withReconcilePrecondition(not_met_reconcile_condition)
.addDependentResource(gcDeleter).dependsOn(dr1)
.build();

var res = workflow.reconcile(new TestCustomResource(), mockContext);

Assertions.assertThat(res.getErroredDependents()).isEmpty();
assertThat(executionHistory).deleted(gcDeleter);
}

}