|
16 | 16 | import io.fabric8.kubernetes.client.informers.cache.ItemStore;
|
17 | 17 | import io.javaoperatorsdk.operator.ReconcilerUtils;
|
18 | 18 | import io.javaoperatorsdk.operator.api.config.Utils.Configurator;
|
19 |
| -import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver; |
20 | 19 | import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
|
21 | 20 | import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec;
|
22 | 21 | import io.javaoperatorsdk.operator.api.reconciler.Constants;
|
@@ -224,6 +223,45 @@ private <P extends HasMetadata> ResolvedControllerConfiguration<P> controllerCon
|
224 | 223 | this, informerListLimit);
|
225 | 224 | }
|
226 | 225 |
|
| 226 | + @SuppressWarnings({"unchecked", "rawtypes"}) |
| 227 | + private static List<DependentResourceSpec> dependentResources( |
| 228 | + Workflow annotation, |
| 229 | + ControllerConfiguration<?> parent) { |
| 230 | + final var dependents = annotation.dependents(); |
| 231 | + |
| 232 | + |
| 233 | + if (dependents == null || dependents.length == 0) { |
| 234 | + return Collections.emptyList(); |
| 235 | + } |
| 236 | + |
| 237 | + final var specsMap = new LinkedHashMap<String, DependentResourceSpec>(dependents.length); |
| 238 | + for (Dependent dependent : dependents) { |
| 239 | + final Class<? extends DependentResource> dependentType = dependent.type(); |
| 240 | + |
| 241 | + final var dependentName = getName(dependent.name(), dependentType); |
| 242 | + var spec = specsMap.get(dependentName); |
| 243 | + if (spec != null) { |
| 244 | + throw new IllegalArgumentException( |
| 245 | + "A DependentResource named '" + dependentName + "' already exists: " + spec); |
| 246 | + } |
| 247 | + |
| 248 | + final var name = parent.getName(); |
| 249 | + |
| 250 | + var eventSourceName = dependent.useEventSourceWithName(); |
| 251 | + eventSourceName = Constants.NO_VALUE_SET.equals(eventSourceName) ? null : eventSourceName; |
| 252 | + final var context = Utils.contextFor(name, dependentType, null); |
| 253 | + spec = new DependentResourceSpec(dependentType, dependentName, |
| 254 | + Set.of(dependent.dependsOn()), |
| 255 | + Utils.instantiate(dependent.readyPostcondition(), Condition.class, context), |
| 256 | + Utils.instantiate(dependent.reconcilePrecondition(), Condition.class, context), |
| 257 | + Utils.instantiate(dependent.deletePostcondition(), Condition.class, context), |
| 258 | + Utils.instantiate(dependent.activationCondition(), Condition.class, context), |
| 259 | + eventSourceName); |
| 260 | + specsMap.put(dependentName, spec); |
| 261 | + } |
| 262 | + return specsMap.values().stream().toList(); |
| 263 | + } |
| 264 | + |
227 | 265 | protected boolean createIfNeeded() {
|
228 | 266 | return true;
|
229 | 267 | }
|
|
0 commit comments