dependentResources) {
- for (var dependentResource : dependentResources) {
- var dependsOn = getNodeByDependentResource(dependentResource);
- currentNode.addDependsOnRelation(dependsOn);
- }
- return this;
- }
-
- public WorkflowBuilder dependsOn(DependentResource... dependentResources) {
- if (dependentResources != null) {
- return dependsOn(new HashSet<>(Arrays.asList(dependentResources)));
- }
- return this;
+ public WorkflowNodeConfigurationBuilder addDependentResourceAndConfigure(
+ DependentResource dependentResource) {
+ final var currentNode = doAddDependentResource(dependentResource);
+ return new WorkflowNodeConfigurationBuilder(currentNode);
}
- public WorkflowBuilder
withReconcilePrecondition(Condition reconcilePrecondition) {
- currentNode.setReconcilePrecondition(reconcilePrecondition);
- return this;
- }
-
- public WorkflowBuilder
withReadyPostcondition(Condition readyPostcondition) {
- currentNode.setReadyPostcondition(readyPostcondition);
- return this;
- }
-
- public WorkflowBuilder
withDeletePostcondition(Condition deletePostcondition) {
- currentNode.setDeletePostcondition(deletePostcondition);
+ public WorkflowBuilder
addDependentResource(DependentResource dependentResource) {
+ doAddDependentResource(dependentResource);
return this;
}
- public WorkflowBuilder
withActivationCondition(Condition activationCondition) {
- currentNode.setActivationCondition(activationCondition);
- return this;
+ private DependentResourceNode doAddDependentResource(DependentResource dependentResource) {
+ final var currentNode = new DependentResourceNode<>(dependentResource);
+ isCleaner = isCleaner || dependentResource.isDeletable();
+ final var actualName = dependentResource.name();
+ dependentResourceNodes.put(actualName, currentNode);
+ return currentNode;
}
DependentResourceNode getNodeByDependentResource(DependentResource, ?> dependentResource) {
@@ -89,4 +64,70 @@ DefaultWorkflow
buildAsDefaultWorkflow() {
return new DefaultWorkflow(new HashSet<>(dependentResourceNodes.values()),
throwExceptionAutomatically, isCleaner);
}
+
+ public class WorkflowNodeConfigurationBuilder {
+ private final DependentResourceNode currentNode;
+
+ private WorkflowNodeConfigurationBuilder(DependentResourceNode currentNode) {
+ this.currentNode = currentNode;
+ }
+
+ public WorkflowBuilder
addDependentResource(DependentResource, ?> dependentResource) {
+ return WorkflowBuilder.this.addDependentResource(dependentResource);
+ }
+
+ public WorkflowNodeConfigurationBuilder addDependentResourceAndConfigure(
+ DependentResource, ?> dependentResource) {
+ final var currentNode = WorkflowBuilder.this.doAddDependentResource(dependentResource);
+ return new WorkflowNodeConfigurationBuilder(currentNode);
+ }
+
+ public Workflow
build() {
+ return WorkflowBuilder.this.build();
+ }
+
+ DefaultWorkflow
buildAsDefaultWorkflow() {
+ return WorkflowBuilder.this.buildAsDefaultWorkflow();
+ }
+
+ public WorkflowBuilder
withThrowExceptionFurther(boolean throwExceptionFurther) {
+ return WorkflowBuilder.this.withThrowExceptionFurther(throwExceptionFurther);
+ }
+
+ public WorkflowNodeConfigurationBuilder toDependOn(Set dependentResources) {
+ for (var dependentResource : dependentResources) {
+ var dependsOn = getNodeByDependentResource(dependentResource);
+ currentNode.addDependsOnRelation(dependsOn);
+ }
+ return this;
+ }
+
+ public WorkflowNodeConfigurationBuilder toDependOn(DependentResource... dependentResources) {
+ if (dependentResources != null) {
+ return toDependOn(new HashSet<>(Arrays.asList(dependentResources)));
+ }
+ return this;
+ }
+
+ public WorkflowNodeConfigurationBuilder withReconcilePrecondition(
+ Condition reconcilePrecondition) {
+ currentNode.setReconcilePrecondition(reconcilePrecondition);
+ return this;
+ }
+
+ public WorkflowNodeConfigurationBuilder withReadyPostcondition(Condition readyPostcondition) {
+ currentNode.setReadyPostcondition(readyPostcondition);
+ return this;
+ }
+
+ public WorkflowNodeConfigurationBuilder withDeletePostcondition(Condition deletePostcondition) {
+ currentNode.setDeletePostcondition(deletePostcondition);
+ return this;
+ }
+
+ public WorkflowNodeConfigurationBuilder withActivationCondition(Condition activationCondition) {
+ currentNode.setActivationCondition(activationCondition);
+ return this;
+ }
+ }
}
diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java
index ed6ba5f80c..7d4666940a 100644
--- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java
+++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowCleanupExecutorTest.java
@@ -54,9 +54,9 @@ void setup() {
void cleanUpDiamondWorkflow() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dr1).dependsOn(dd1)
- .addDependentResource(dd2).dependsOn(dd1)
- .addDependentResource(dd3).dependsOn(dr1, dd2)
+ .addDependentResourceAndConfigure(dr1).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd3).toDependOn(dr1, dd2)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -73,9 +73,9 @@ void cleanUpDiamondWorkflow() {
void dontDeleteIfDependentErrored() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1)
- .addDependentResource(dd3).dependsOn(dd2)
- .addDependentResource(errorDD).dependsOn(dd2)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd3).toDependOn(dd2)
+ .addDependentResourceAndConfigure(errorDD).toDependOn(dd2)
.withThrowExceptionFurther(false)
.build();
@@ -95,7 +95,8 @@ void dontDeleteIfDependentErrored() {
void cleanupConditionTrivialCase() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1).withDeletePostcondition(notMetCondition)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .withDeletePostcondition(notMetCondition)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -110,7 +111,7 @@ void cleanupConditionTrivialCase() {
void cleanupConditionMet() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1).withDeletePostcondition(metCondition)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1).withDeletePostcondition(metCondition)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -126,9 +127,10 @@ void cleanupConditionMet() {
void cleanupConditionDiamondWorkflow() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1)
- .addDependentResource(dd3).dependsOn(dd1).withDeletePostcondition(notMetCondition)
- .addDependentResource(dd4).dependsOn(dd2, dd3)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd3).toDependOn(dd1)
+ .withDeletePostcondition(notMetCondition)
+ .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -162,10 +164,10 @@ void dontDeleteIfGarbageCollected() {
void ifDependentActiveDependentNormallyDeleted() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1)
- .addDependentResource(dd3).dependsOn(dd1)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.withActivationCondition(metCondition)
- .addDependentResource(dd4).dependsOn(dd2, dd3)
+ .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -182,11 +184,11 @@ void ifDependentActiveDependentNormallyDeleted() {
void ifDependentActiveDeletePostConditionIsChecked() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1)
- .addDependentResource(dd3).dependsOn(dd1)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.withDeletePostcondition(notMetCondition)
.withActivationCondition(metCondition)
- .addDependentResource(dd4).dependsOn(dd2, dd3)
+ .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -206,10 +208,10 @@ void ifDependentActiveDeletePostConditionIsChecked() {
void ifDependentInactiveDeleteIsNotCalled() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1)
- .addDependentResource(dd3).dependsOn(dd1)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.withActivationCondition(notMetCondition)
- .addDependentResource(dd4).dependsOn(dd2, dd3)
+ .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -225,11 +227,11 @@ void ifDependentInactiveDeleteIsNotCalled() {
void ifDependentInactiveDeletePostConditionNotChecked() {
var workflow = new WorkflowBuilder()
.addDependentResource(dd1)
- .addDependentResource(dd2).dependsOn(dd1)
- .addDependentResource(dd3).dependsOn(dd1)
+ .addDependentResourceAndConfigure(dd2).toDependOn(dd1)
+ .addDependentResourceAndConfigure(dd3).toDependOn(dd1)
.withDeletePostcondition(notMetCondition)
.withActivationCondition(notMetCondition)
- .addDependentResource(dd4).dependsOn(dd2, dd3)
+ .addDependentResourceAndConfigure(dd4).toDependOn(dd2, dd3)
.build();
var res = workflow.cleanup(new TestCustomResource(), mockContext);
@@ -243,7 +245,7 @@ void ifDependentInactiveDeletePostConditionNotChecked() {
@Test
void singleInactiveDependent() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dd1)
+ .addDependentResourceAndConfigure(dd1)
.withActivationCondition(notMetCondition)
.build();
diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java
index dce39f2050..aedfe44df9 100644
--- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java
+++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutorTest.java
@@ -53,7 +53,7 @@ void reconcileTopLevelResources() {
void reconciliationWithSimpleDependsOn() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -70,8 +70,8 @@ void reconciliationWithTwoTheDependsOns() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
- .addDependentResource(dr3).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -88,9 +88,9 @@ void reconciliationWithTwoTheDependsOns() {
void diamondShareWorkflowReconcile() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
- .addDependentResource(dr3).dependsOn(dr1)
- .addDependentResource(dr4).dependsOn(dr3).dependsOn(dr2)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr4).toDependOn(dr3).toDependOn(dr2)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -128,8 +128,8 @@ void exceptionHandlingSimpleCases() {
void dependentsOnErroredResourceNotReconciled() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(drError).dependsOn(dr1)
- .addDependentResource(dr2).dependsOn(drError)
+ .addDependentResourceAndConfigure(drError).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(drError)
.withThrowExceptionFurther(false)
.build();
@@ -148,9 +148,9 @@ void oneBranchErrorsOtherCompletes() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(drError).dependsOn(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
- .addDependentResource(dr3).dependsOn(dr2)
+ .addDependentResourceAndConfigure(drError).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr2)
.withThrowExceptionFurther(false)
.build();
@@ -169,7 +169,7 @@ void onlyOneDependsOnErroredResourceNotReconciled() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
.addDependentResource(drError)
- .addDependentResource(dr2).dependsOn(drError, dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(drError, dr1)
.withThrowExceptionFurther(false)
.build();
@@ -196,9 +196,9 @@ public Result detailedIsMet(
};
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1).withReconcilePrecondition(unmetWithResult)
- .addDependentResource(dr2).withReconcilePrecondition(metCondition)
- .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition)
+ .addDependentResourceAndConfigure(dr1).withReconcilePrecondition(unmetWithResult)
+ .addDependentResourceAndConfigure(dr2).withReconcilePrecondition(metCondition)
+ .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -216,9 +216,9 @@ public Result detailedIsMet(
void triangleOnceConditionNotMet() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
- .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition)
- .dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
+ .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
+ .toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -235,11 +235,11 @@ void reconcileConditionTransitiveDelete() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.withReconcilePrecondition(notMetCondition)
- .addDependentResource(drDeleter).dependsOn(dr2)
+ .addDependentResourceAndConfigure(drDeleter).toDependOn(dr2)
.withReconcilePrecondition(metCondition)
- .addDependentResource(drDeleter2).dependsOn(drDeleter)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.withReconcilePrecondition(metCondition)
.build();
@@ -261,8 +261,8 @@ void reconcileConditionAlsoErrorDependsOn() {
var workflow = new WorkflowBuilder()
.addDependentResource(drError)
- .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition)
- .addDependentResource(drDeleter2).dependsOn(drError, drDeleter)
+ .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(drError, drDeleter)
.withReconcilePrecondition(metCondition)
.withThrowExceptionFurther(false)
.build();
@@ -284,8 +284,8 @@ void reconcileConditionAlsoErrorDependsOn() {
void oneDependsOnConditionNotMet() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(dr2).withReconcilePrecondition(notMetCondition)
- .addDependentResource(drDeleter).dependsOn(dr1, dr2)
+ .addDependentResourceAndConfigure(dr2).withReconcilePrecondition(notMetCondition)
+ .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1, dr2)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -303,9 +303,9 @@ void deletedIfReconcileConditionNotMet() {
TestDeleterDependent drDeleter2 = new TestDeleterDependent("DR_DELETER_2");
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(drDeleter).dependsOn(dr1)
+ .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1)
.withReconcilePrecondition(notMetCondition)
- .addDependentResource(drDeleter2).dependsOn(dr1, drDeleter)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(dr1, drDeleter)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -327,11 +327,11 @@ void deleteDoneInReverseOrder() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition)
- .dependsOn(dr1)
- .addDependentResource(drDeleter2).dependsOn(drDeleter)
- .addDependentResource(drDeleter3).dependsOn(drDeleter)
- .addDependentResource(drDeleter4).dependsOn(drDeleter3)
+ .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
+ .toDependOn(dr1)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
+ .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter)
+ .addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -353,11 +353,11 @@ void diamondDeleteWithPostConditionInMiddle() {
TestDeleterDependent drDeleter4 = new TestDeleterDependent("DR_DELETER_4");
var workflow = new WorkflowBuilder()
- .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition)
- .addDependentResource(drDeleter2).dependsOn(drDeleter)
- .addDependentResource(drDeleter3).dependsOn(drDeleter)
+ .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
+ .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter)
.withDeletePostcondition(this.notMetCondition)
- .addDependentResource(drDeleter4).dependsOn(drDeleter3, drDeleter2)
+ .addDependentResourceAndConfigure(drDeleter4).toDependOn(drDeleter3, drDeleter2)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -377,10 +377,10 @@ void diamondDeleteErrorInMiddle() {
TestDeleterDependent drDeleter3 = new TestDeleterDependent("DR_DELETER_3");
var workflow = new WorkflowBuilder()
- .addDependentResource(drDeleter).withReconcilePrecondition(notMetCondition)
- .addDependentResource(drDeleter2).dependsOn(drDeleter)
- .addDependentResource(errorDD).dependsOn(drDeleter)
- .addDependentResource(drDeleter3).dependsOn(errorDD, drDeleter2)
+ .addDependentResourceAndConfigure(drDeleter).withReconcilePrecondition(notMetCondition)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
+ .addDependentResourceAndConfigure(errorDD).toDependOn(drDeleter)
+ .addDependentResourceAndConfigure(drDeleter3).toDependOn(errorDD, drDeleter2)
.withThrowExceptionFurther(false)
.build();
@@ -398,8 +398,8 @@ void diamondDeleteErrorInMiddle() {
@Test
void readyConditionTrivialCase() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1).withReadyPostcondition(metCondition)
- .addDependentResource(dr2).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr1).withReadyPostcondition(metCondition)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -414,8 +414,8 @@ void readyConditionTrivialCase() {
@Test
void readyConditionNotMetTrivialCase() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1).withReadyPostcondition(notMetCondition)
- .addDependentResource(dr2).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -432,9 +432,9 @@ void readyConditionNotMetTrivialCase() {
void readyConditionNotMetInOneParent() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1).withReadyPostcondition(notMetCondition)
+ .addDependentResourceAndConfigure(dr1).withReadyPostcondition(notMetCondition)
.addDependentResource(dr2)
- .addDependentResource(dr3).dependsOn(dr1, dr2)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr1, dr2)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -449,9 +449,10 @@ void readyConditionNotMetInOneParent() {
void diamondShareWithReadyCondition() {
var workflow = new WorkflowBuilder()
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1).withReadyPostcondition(notMetCondition)
- .addDependentResource(dr3).dependsOn(dr1)
- .addDependentResource(dr4).dependsOn(dr2, dr3)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
+ .withReadyPostcondition(notMetCondition)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr4).toDependOn(dr2, dr3)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -469,7 +470,7 @@ void diamondShareWithReadyCondition() {
@Test
void garbageCollectedResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
var workflow = new WorkflowBuilder()
- .addDependentResource(gcDeleter).withReconcilePrecondition(notMetCondition)
+ .addDependentResourceAndConfigure(gcDeleter).withReconcilePrecondition(notMetCondition)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -481,8 +482,8 @@ void garbageCollectedResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
@Test
void garbageCollectedDeepResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1).withReconcilePrecondition(notMetCondition)
- .addDependentResource(gcDeleter).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr1).withReconcilePrecondition(notMetCondition)
+ .addDependentResourceAndConfigure(gcDeleter).toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -494,7 +495,7 @@ void garbageCollectedDeepResourceIsDeletedIfReconcilePreconditionDoesNotHold() {
@Test
void notReconciledIfActivationConditionNotMet() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1)
+ .addDependentResourceAndConfigure(dr1)
.withActivationCondition(notMetCondition)
.addDependentResource(dr2)
.build();
@@ -508,10 +509,10 @@ void notReconciledIfActivationConditionNotMet() {
@Test
void dependentsOnANonActiveDependentNotReconciled() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1)
+ .addDependentResourceAndConfigure(dr1)
.withActivationCondition(notMetCondition)
.addDependentResource(dr2)
- .addDependentResource(dr3).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -523,11 +524,11 @@ void dependentsOnANonActiveDependentNotReconciled() {
@Test
void readyConditionNotCheckedOnNonActiveDependent() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1)
+ .addDependentResourceAndConfigure(dr1)
.withActivationCondition(notMetCondition)
.withReadyPostcondition(notMetCondition)
.addDependentResource(dr2)
- .addDependentResource(dr3).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr1)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -541,7 +542,7 @@ void reconcilePreconditionNotCheckedOnNonActiveDependent() {
var precondition = mock(Condition.class);
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1)
+ .addDependentResourceAndConfigure(dr1)
.withActivationCondition(notMetCondition)
.withReconcilePrecondition(precondition)
.build();
@@ -557,11 +558,11 @@ void deletesDependentsOfNonActiveDependentButNotTheNonActive() {
TestDeleterDependent drDeleter3 = new TestDeleterDependent("DR_DELETER_3");
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1).withActivationCondition(notMetCondition)
- .addDependentResource(drDeleter).dependsOn(dr1)
- .addDependentResource(drDeleter2).dependsOn(drDeleter)
+ .addDependentResourceAndConfigure(dr1).withActivationCondition(notMetCondition)
+ .addDependentResourceAndConfigure(drDeleter).toDependOn(dr1)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.withActivationCondition(notMetCondition)
- .addDependentResource(drDeleter3).dependsOn(drDeleter2)
+ .addDependentResourceAndConfigure(drDeleter3).toDependOn(drDeleter2)
.build();
var res = workflow.reconcile(new TestCustomResource(), mockContext);
@@ -580,8 +581,8 @@ void activationConditionOnlyCalledOnceOnDeleteDependents() {
when(condition.isMet(any(), any(), any())).thenReturn(false);
var workflow = new WorkflowBuilder()
- .addDependentResource(drDeleter).withActivationCondition(condition)
- .addDependentResource(drDeleter2).dependsOn(drDeleter)
+ .addDependentResourceAndConfigure(drDeleter).withActivationCondition(condition)
+ .addDependentResourceAndConfigure(drDeleter2).toDependOn(drDeleter)
.build();
workflow.reconcile(new TestCustomResource(), mockContext);
@@ -612,7 +613,7 @@ public boolean isSuccess() {
}
};
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1)
+ .addDependentResourceAndConfigure(dr1)
.withReadyPostcondition(resultCondition)
.build();
@@ -642,7 +643,7 @@ public boolean isSuccess() {
}
};
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1)
+ .addDependentResourceAndConfigure(dr1)
.withReadyPostcondition(resultCondition)
.build();
@@ -659,7 +660,7 @@ public boolean isSuccess() {
@Test
void shouldReturnEmptyIfNoConditionResultExists() {
var workflow = new WorkflowBuilder()
- .addDependentResource(dr1)
+ .addDependentResourceAndConfigure(dr1)
.withReadyPostcondition(notMetCondition)
.build();
diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java
index d6e14a1645..203c1714f2 100644
--- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java
+++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java
@@ -1,8 +1,6 @@
package io.javaoperatorsdk.operator.processing.dependent.workflow;
import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
@@ -22,8 +20,6 @@
@SuppressWarnings("rawtypes")
class WorkflowTest {
- ExecutorService executorService = Executors.newCachedThreadPool();
-
@Test
void zeroTopLevelDRShouldThrowException() {
var dr1 = mockDependent("dr1");
@@ -31,10 +27,10 @@ void zeroTopLevelDRShouldThrowException() {
var dr3 = mockDependent("dr3");
var cyclicWorkflowBuilderSetup = new WorkflowBuilder()
- .addDependentResource(dr1).dependsOn()
- .addDependentResource(dr2).dependsOn(dr1)
- .addDependentResource(dr3).dependsOn(dr2)
- .addDependentResource(dr1).dependsOn(dr2);
+ .addDependentResourceAndConfigure(dr1).toDependOn()
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
+ .addDependentResourceAndConfigure(dr3).toDependOn(dr2)
+ .addDependentResourceAndConfigure(dr1).toDependOn(dr2);
assertThrows(IllegalStateException.class,
cyclicWorkflowBuilderSetup::build);
@@ -49,7 +45,7 @@ void calculatesTopLevelResources() {
var workflow = new WorkflowBuilder()
.addDependentResource(independentDR)
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.buildAsDefaultWorkflow();
Set topResources =
@@ -69,7 +65,7 @@ void calculatesBottomLevelResources() {
final var workflow = new WorkflowBuilder()
.addDependentResource(independentDR)
.addDependentResource(dr1)
- .addDependentResource(dr2).dependsOn(dr1)
+ .addDependentResourceAndConfigure(dr2).toDependOn(dr1)
.buildAsDefaultWorkflow();
Set bottomResources =
diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java
index 15343793fd..4dc75122f2 100644
--- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java
+++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageDependentsWorkflowReconciler.java
@@ -46,7 +46,8 @@ public WebPageDependentsWorkflowReconciler(KubernetesClient kubernetesClient) {
.addDependentResource(configMapDR)
.addDependentResource(deploymentDR)
.addDependentResource(serviceDR)
- .addDependentResource(ingressDR).withReconcilePrecondition(new ExposedIngressCondition())
+ .addDependentResourceAndConfigure(ingressDR)
+ .withReconcilePrecondition(new ExposedIngressCondition())
.build();
}
diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java
index 580d529a72..d2475b983f 100644
--- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java
+++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStandaloneDependentsReconciler.java
@@ -109,7 +109,7 @@ private Workflow createDependentResourcesAndWorkflow() {
.addDependentResource(configMapDR)
.addDependentResource(deploymentDR)
.addDependentResource(serviceDR)
- .addDependentResource(ingressDR)
+ .addDependentResourceAndConfigure(ingressDR)
// prevent the Ingress from being created based on the linked condition (here: only if the
// `exposed` flag is set in the primary resource), delete the Ingress if it already exists
// and the condition becomes false