|
1 | 1 | package io.javaoperatorsdk.operator.api.config;
|
2 | 2 |
|
| 3 | +import java.lang.reflect.InvocationTargetException; |
3 | 4 | import java.time.Duration;
|
4 | 5 | import java.util.Arrays;
|
5 | 6 | import java.util.Collections;
|
|
19 | 20 | import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
|
20 | 21 | import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent;
|
21 | 22 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
|
| 23 | +import io.javaoperatorsdk.operator.api.reconciler.dependent.VoidCondition; |
22 | 24 | import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
|
23 | 25 | import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource;
|
24 | 26 | import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig;
|
| 27 | +import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; |
25 | 28 | import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;
|
26 | 29 | import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilters;
|
27 | 30 |
|
@@ -172,19 +175,46 @@ public List<DependentResourceSpec> getDependentResources() {
|
172 | 175 | }
|
173 | 176 |
|
174 | 177 | final var name = getName(dependent, dependentType);
|
175 |
| - final var spec = specsMap.get(name); |
| 178 | + var spec = specsMap.get(name); |
176 | 179 | if (spec != null) {
|
177 | 180 | throw new IllegalArgumentException(
|
178 | 181 | "A DependentResource named: " + name + " already exists: " + spec);
|
179 | 182 | }
|
180 |
| - specsMap.put(name, new DependentResourceSpec(dependentType, config, name)); |
| 183 | + spec = new DependentResourceSpec(dependentType, config, name); |
| 184 | + spec.setDependsOn(Set.of(dependent.dependsOn())); |
| 185 | + addConditions(spec, dependent); |
| 186 | + specsMap.put(name, spec); |
181 | 187 | }
|
182 | 188 |
|
183 | 189 | specs = specsMap.values().stream().collect(Collectors.toUnmodifiableList());
|
184 | 190 | }
|
185 | 191 | return specs;
|
186 | 192 | }
|
187 | 193 |
|
| 194 | + @SuppressWarnings("unchecked") |
| 195 | + private void addConditions(DependentResourceSpec spec, Dependent dependent) { |
| 196 | + if (dependent.deletePostcondition() != VoidCondition.class) { |
| 197 | + spec.setDeletePostCondition(instantiateCondition(dependent.deletePostcondition())); |
| 198 | + } |
| 199 | + if (dependent.readyPostcondition() != VoidCondition.class) { |
| 200 | + spec.setReadyPostcondition(instantiateCondition(dependent.readyPostcondition())); |
| 201 | + } |
| 202 | + if (dependent.reconcilePrecondition() != VoidCondition.class) { |
| 203 | + spec.setReconcilePrecondition(instantiateCondition(dependent.reconcilePrecondition())); |
| 204 | + } |
| 205 | + } |
| 206 | + |
| 207 | + private Condition<?, ?> instantiateCondition(Class<? extends Condition> condition) { |
| 208 | + try { |
| 209 | + return condition.getDeclaredConstructor().newInstance(); |
| 210 | + } catch (InstantiationException |
| 211 | + | IllegalAccessException |
| 212 | + | InvocationTargetException |
| 213 | + | NoSuchMethodException e) { |
| 214 | + throw new OperatorException(e); |
| 215 | + } |
| 216 | + } |
| 217 | + |
188 | 218 | private String getName(Dependent dependent, Class<? extends DependentResource> dependentType) {
|
189 | 219 | var name = dependent.name();
|
190 | 220 | if (name.isBlank()) {
|
|
0 commit comments