Skip to content

fix: workflow builder isCleaner bug #1872

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 1 commit into from
Apr 25, 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 @@ -22,7 +22,7 @@ public class WorkflowBuilder<P extends HasMetadata> {

public WorkflowBuilder<P> addDependentResource(DependentResource dependentResource) {
currentNode = new DependentResourceNode<>(dependentResource);
isCleaner = dependentResource.isDeletable();
isCleaner = isCleaner || dependentResource.isDeletable();
final var name = currentNode.getName();
dependentResourceNodes.put(name, currentNode);
return this;
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
@@ -0,0 +1,27 @@
package io.javaoperatorsdk.operator.processing.dependent.workflow;

import org.junit.jupiter.api.Test;

import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

class WorkflowBuilderTest {

@Test
void workflowIsCleanerIfAtLeastOneDRIsCleaner() {
var dr = mock(DependentResource.class);
var deleter = mock(DependentResource.class);
when(deleter.isDeletable()).thenReturn(true);

var workflow = new WorkflowBuilder<TestCustomResource>()
.addDependentResource(deleter)
.addDependentResource(dr)
.build();

assertThat(workflow.hasCleaner()).isTrue();
}

}