Skip to content

Commit fc470e2

Browse files
committed
constructing workflow
Signed-off-by: Attila Mészáros <[email protected]>
1 parent a5ec5a2 commit fc470e2

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ private static List<DependentResourceSpec> dependentResources(
201201
Utils.instantiate(dependent.reconcilePrecondition(), Condition.class, context),
202202
Utils.instantiate(dependent.deletePostcondition(), Condition.class, context),
203203
Utils.instantiate(dependent.activationCondition(), Condition.class, context),
204-
eventSourceName);
204+
eventSourceName, dependent.optional());
205+
205206
specsMap.put(dependentName, spec);
206207
}
207208
return specsMap.values().stream().collect(Collectors.toUnmodifiableList());

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceSpec.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ public class DependentResourceSpec<R, P extends HasMetadata> {
2626

2727
private final String useEventSourceWithName;
2828

29+
private final boolean optional;
30+
2931
public DependentResourceSpec(Class<? extends DependentResource<R, P>> dependentResourceClass,
3032
String name, Set<String> dependsOn, Condition<?, ?> readyCondition,
3133
Condition<?, ?> reconcileCondition, Condition<?, ?> deletePostCondition,
32-
Condition<?, ?> activationCondition, String useEventSourceWithName) {
34+
Condition<?, ?> activationCondition, String useEventSourceWithName, boolean optional) {
3335
this.dependentResourceClass = dependentResourceClass;
3436
this.name = name;
3537
this.dependsOn = dependsOn;
@@ -38,6 +40,13 @@ public DependentResourceSpec(Class<? extends DependentResource<R, P>> dependentR
3840
this.deletePostCondition = deletePostCondition;
3941
this.activationCondition = activationCondition;
4042
this.useEventSourceWithName = useEventSourceWithName;
43+
this.optional = optional;
44+
45+
if (this.optional && activationCondition != null) {
46+
throw new IllegalArgumentException(
47+
"Dependent resource cannot be both optional and contain activation condition. Dependent resource name: "
48+
+ name + " class: " + dependentResourceClass);
49+
}
4150
}
4251

4352
public Class<? extends DependentResource<R, P>> getDependentResourceClass() {
@@ -98,4 +107,8 @@ public Condition getActivationCondition() {
98107
public Optional<String> getUseEventSourceWithName() {
99108
return Optional.ofNullable(useEventSourceWithName);
100109
}
110+
111+
public boolean isOptional() {
112+
return optional;
113+
}
101114
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationCondition.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
public class CRDPresentActivationCondition implements Condition<HasMetadata, HasMetadata> {
2222

23-
public static Retry DEFAULT_EXPIRATION_RETRY = new GenericRetry().setInitialInterval(1000)
23+
public static Retry DEFAULT_EXPIRATION_RETRY = new GenericRetry().setInitialInterval(2000)
2424
.setMaxInterval(1000 * 60 * 60)
2525
.setIntervalMultiplier(2);
2626

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ public boolean isEmpty() {
7878
public Workflow<P> resolve(KubernetesClient client,
7979
ControllerConfiguration<P> configuration) {
8080
final var alreadyResolved = new HashMap<String, DependentResourceNode>(orderedSpecs.size());
81+
82+
// sharing the activation condition so no parallel requests are done for the same CRD
83+
CRDPresentActivationCondition crdPresentActivationCondition =
84+
new CRDPresentActivationCondition();
85+
8186
for (DependentResourceSpec spec : orderedSpecs) {
8287
final var dependentResource = resolve(spec, client, configuration);
8388
final var node = new DependentResourceNode(
8489
spec.getReconcileCondition(),
8590
spec.getDeletePostCondition(),
8691
spec.getReadyCondition(),
87-
spec.getActivationCondition(),
88-
dependentResource);
92+
spec.isOptional() ? crdPresentActivationCondition : spec.getActivationCondition(),
93+
resolve(spec, client, configuration));
8994
alreadyResolved.put(dependentResource.name(), node);
9095
spec.getDependsOn()
9196
.forEach(depend -> node.addDependsOnRelation(alreadyResolved.get(depend)));

Diff for: operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ManagedWorkflowTestUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ManagedWorkflowTestUtils {
2121
@SuppressWarnings("unchecked")
2222
public static DependentResourceSpec createDRS(String name, String... dependOns) {
2323
return new DependentResourceSpec(EmptyTestDependentResource.class, name, Set.of(dependOns),
24-
null, null, null, null, null);
24+
null, null, null, null, null, false);
2525
}
2626

2727
public static DependentResourceSpec createDRSWithTraits(String name,

0 commit comments

Comments
 (0)