Skip to content

Commit d63f308

Browse files
committed
feat: reconcile condition
1 parent 7d6ea08 commit d63f308

File tree

12 files changed

+346
-140
lines changed

12 files changed

+346
-140
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import io.fabric8.kubernetes.api.model.HasMetadata;
44
import io.fabric8.kubernetes.client.CustomResource;
55

6-
public class UpdateControl<T extends HasMetadata> extends BaseControl<UpdateControl<T>> {
6+
public class UpdateControl<P extends HasMetadata> extends BaseControl<UpdateControl<P>> {
77

8-
private final T resource;
8+
private final P resource;
99
private final boolean updateStatus;
1010
private final boolean updateResource;
1111
private final boolean patch;
1212

1313
private UpdateControl(
14-
T resource, boolean updateStatus, boolean updateResource, boolean patch) {
14+
P resource, boolean updateStatus, boolean updateResource, boolean patch) {
1515
if ((updateResource || updateStatus) && resource == null) {
1616
throw new IllegalArgumentException("CustomResource cannot be null in case of update");
1717
}
@@ -92,7 +92,7 @@ public static <T extends HasMetadata> UpdateControl<T> noUpdate() {
9292
return new UpdateControl<>(null, false, false, false);
9393
}
9494

95-
public T getResource() {
95+
public P getResource() {
9696
return resource;
9797
}
9898

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DependentResourceNode.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
import io.fabric8.kubernetes.api.model.HasMetadata;
88
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
99
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.CleanupCondition;
10+
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.ReadyCondition;
1011
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.ReconcileCondition;
1112

1213
public class DependentResourceNode<R, P extends HasMetadata> {
1314

1415
private final DependentResource<R, P> dependentResource;
15-
private ReconcileCondition reconcileCondition;
16+
private ReconcileCondition<P> reconcileCondition;
1617
private CleanupCondition cleanupCondition;
17-
private List<DependsOnRelation> dependsOnRelations = new ArrayList<>(1);
18+
private ReadyCondition<R, P> readyCondition;
19+
private List<DependentResourceNode> dependsOn = new ArrayList<>(1);
1820

1921
public DependentResourceNode(DependentResource<R, P> dependentResource) {
2022
this(dependentResource, null, null);
@@ -26,7 +28,7 @@ public DependentResourceNode(DependentResource<R, P> dependentResource,
2628
}
2729

2830
public DependentResourceNode(DependentResource<R, P> dependentResource,
29-
ReconcileCondition reconcileCondition, CleanupCondition cleanupCondition) {
31+
ReconcileCondition<P> reconcileCondition, CleanupCondition cleanupCondition) {
3032
this.dependentResource = dependentResource;
3133
this.reconcileCondition = reconcileCondition;
3234
this.cleanupCondition = cleanupCondition;
@@ -36,24 +38,24 @@ public DependentResource<R, P> getDependentResource() {
3638
return dependentResource;
3739
}
3840

39-
public Optional<ReconcileCondition> getReconcileCondition() {
41+
public Optional<ReconcileCondition<P>> getReconcileCondition() {
4042
return Optional.ofNullable(reconcileCondition);
4143
}
4244

4345
public Optional<CleanupCondition> getCleanupCondition() {
4446
return Optional.ofNullable(cleanupCondition);
4547
}
4648

47-
public void setDependsOnRelations(List<DependsOnRelation> dependsOnRelations) {
48-
this.dependsOnRelations = dependsOnRelations;
49+
public void setDependsOn(List<DependentResourceNode> dependsOn) {
50+
this.dependsOn = dependsOn;
4951
}
5052

51-
public List<DependsOnRelation> getDependsOnRelations() {
52-
return dependsOnRelations;
53+
public List<DependentResourceNode> getDependsOn() {
54+
return dependsOn;
5355
}
5456

55-
public void addDependsOnRelation(DependsOnRelation dependsOnRelation) {
56-
dependsOnRelations.add(dependsOnRelation);
57+
public void addDependsOnRelation(DependentResourceNode node) {
58+
dependsOn.add(node);
5759
}
5860

5961
@Override
@@ -62,4 +64,24 @@ public String toString() {
6264
"dependentResource=" + dependentResource +
6365
'}';
6466
}
67+
68+
public DependentResourceNode<R, P> setReconcileCondition(
69+
ReconcileCondition<P> reconcileCondition) {
70+
this.reconcileCondition = reconcileCondition;
71+
return this;
72+
}
73+
74+
public DependentResourceNode<R, P> setCleanupCondition(CleanupCondition cleanupCondition) {
75+
this.cleanupCondition = cleanupCondition;
76+
return this;
77+
}
78+
79+
public ReadyCondition<R, P> getReadyCondition() {
80+
return readyCondition;
81+
}
82+
83+
public DependentResourceNode<R, P> setReadyCondition(ReadyCondition<R, P> readyCondition) {
84+
this.readyCondition = readyCondition;
85+
return this;
86+
}
6587
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package io.javaoperatorsdk.operator.processing.dependent.workflow;
22

3-
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.WaitCondition;
3+
import io.javaoperatorsdk.operator.processing.dependent.workflow.condition.ReadyCondition;
44

55
public class DependsOnRelation {
66

77
private DependentResourceNode<?, ?> owner;
88
private DependentResourceNode<?, ?> dependsOn;
9-
private WaitCondition waitCondition;
9+
private ReadyCondition readyCondition;
1010

1111
public DependsOnRelation() {}
1212

@@ -16,10 +16,10 @@ public DependsOnRelation(DependentResourceNode<?, ?> owner,
1616
}
1717

1818
public DependsOnRelation(DependentResourceNode<?, ?> owner, DependentResourceNode<?, ?> dependsOn,
19-
WaitCondition waitCondition) {
19+
ReadyCondition readyCondition) {
2020
this.owner = owner;
2121
this.dependsOn = dependsOn;
22-
this.waitCondition = waitCondition;
22+
this.readyCondition = readyCondition;
2323
}
2424

2525
public DependentResourceNode<?, ?> getOwner() {
@@ -30,7 +30,7 @@ public DependsOnRelation(DependentResourceNode<?, ?> owner, DependentResourceNod
3030
return dependsOn;
3131
}
3232

33-
public WaitCondition getWaitCondition() {
34-
return waitCondition;
33+
public ReadyCondition getWaitCondition() {
34+
return readyCondition;
3535
}
3636
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/Workflow.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public void cleanup(P resource, Context<P> context) {
5656
private void preprocessForReconcile() {
5757
dependents = new ConcurrentHashMap<>(dependentResourceNodes.size());
5858
for (DependentResourceNode<?, ?> node : dependentResourceNodes) {
59-
if (node.getDependsOnRelations().isEmpty()) {
59+
if (node.getDependsOn().isEmpty()) {
6060
topLevelResources.add(node);
6161
} else {
62-
for (DependsOnRelation relation : node.getDependsOnRelations()) {
63-
dependents.computeIfAbsent(relation.getDependsOn(), dr -> new ArrayList<>());
64-
dependents.get(relation.getDependsOn()).add(relation.getOwner());
62+
for (DependentResourceNode<?, ?> dependsOn : node.getDependsOn()) {
63+
dependents.computeIfAbsent(dependsOn, dr -> new ArrayList<>());
64+
dependents.get(dependsOn).add(node);
6565
}
6666
}
6767
}

0 commit comments

Comments
 (0)