|
18 | 18 | import io.javaoperatorsdk.operator.RegisteredController;
|
19 | 19 | import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
|
20 | 20 | import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
|
| 21 | +import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec; |
21 | 22 | import io.javaoperatorsdk.operator.api.monitoring.Metrics;
|
22 | 23 | import io.javaoperatorsdk.operator.api.monitoring.Metrics.ControllerExecution;
|
23 | 24 | import io.javaoperatorsdk.operator.api.reconciler.*;
|
24 | 25 | import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceNotFoundException;
|
25 | 26 | import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceProvider;
|
26 | 27 | import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceReferencer;
|
27 |
| -import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedDependentResourceContext; |
| 28 | +import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedWorkflowAndDependentResourceContext; |
28 | 29 | import io.javaoperatorsdk.operator.health.ControllerHealthInfo;
|
29 | 30 | import io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow;
|
30 | 31 | import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowCleanupResult;
|
@@ -131,8 +132,8 @@ public Map<String, Object> metadata() {
|
131 | 132 | public UpdateControl<P> execute() throws Exception {
|
132 | 133 | initContextIfNeeded(resource, context);
|
133 | 134 | configuration.getWorkflowSpec().ifPresent(ws -> {
|
134 |
| - if (!ws.isExplicitInvocation()) { |
135 |
| - invokeManagedWorkflow(resource, context); |
| 135 | + if (!isWorkflowExplicitInvocation()) { |
| 136 | + reconcileManagedWorkflow(resource, context); |
136 | 137 | }
|
137 | 138 | });
|
138 | 139 | return reconciler.reconcile(resource, context);
|
@@ -174,12 +175,14 @@ public Map<String, Object> metadata() {
|
174 | 175 | public DeleteControl execute() {
|
175 | 176 | initContextIfNeeded(resource, context);
|
176 | 177 | WorkflowCleanupResult workflowCleanupResult = null;
|
177 |
| - if (managedWorkflow.hasCleaner()) { |
178 |
| - workflowCleanupResult = managedWorkflow.cleanup(resource, context); |
179 |
| - ((DefaultManagedDependentResourceContext) context.managedDependentResourceContext()) |
180 |
| - .setWorkflowCleanupResult(workflowCleanupResult); |
181 |
| - workflowCleanupResult.throwAggregateExceptionIfErrorsPresent(); |
| 178 | + |
| 179 | + // The cleanup is called also when explicit invocation is true, but the cleaner is not |
| 180 | + // implemented |
| 181 | + if (!isCleaner |
| 182 | + || !isWorkflowExplicitInvocation()) { |
| 183 | + workflowCleanupResult = cleanupManagedWorkflow(resource, context); |
182 | 184 | }
|
| 185 | + |
183 | 186 | if (isCleaner) {
|
184 | 187 | var cleanupResult = ((Cleaner<P>) reconciler).cleanup(resource, context);
|
185 | 188 | if (!cleanupResult.isRemoveFinalizer()) {
|
@@ -429,12 +432,31 @@ public EventSourceContext<P> eventSourceContext() {
|
429 | 432 | return eventSourceContext;
|
430 | 433 | }
|
431 | 434 |
|
432 |
| - public void invokeManagedWorkflow(P primary, Context<P> context) { |
| 435 | + public void reconcileManagedWorkflow(P primary, Context<P> context) { |
433 | 436 | if (!managedWorkflow.isEmpty()) {
|
434 | 437 | var res = managedWorkflow.reconcile(primary, context);
|
435 |
| - ((DefaultManagedDependentResourceContext) context.managedDependentResourceContext()) |
| 438 | + ((DefaultManagedWorkflowAndDependentResourceContext) context |
| 439 | + .managedWorkflowAndDependentResourceContext()) |
436 | 440 | .setWorkflowExecutionResult(res);
|
437 | 441 | res.throwAggregateExceptionIfErrorsPresent();
|
438 | 442 | }
|
439 | 443 | }
|
| 444 | + |
| 445 | + public WorkflowCleanupResult cleanupManagedWorkflow(P resource, Context<P> context) { |
| 446 | + if (managedWorkflow.hasCleaner()) { |
| 447 | + var workflowCleanupResult = managedWorkflow.cleanup(resource, context); |
| 448 | + ((DefaultManagedWorkflowAndDependentResourceContext) context |
| 449 | + .managedWorkflowAndDependentResourceContext()) |
| 450 | + .setWorkflowCleanupResult(workflowCleanupResult); |
| 451 | + workflowCleanupResult.throwAggregateExceptionIfErrorsPresent(); |
| 452 | + return workflowCleanupResult; |
| 453 | + } else { |
| 454 | + return null; |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + public boolean isWorkflowExplicitInvocation() { |
| 459 | + return configuration.getWorkflowSpec().map(WorkflowSpec::isExplicitInvocation) |
| 460 | + .orElse(false); |
| 461 | + } |
440 | 462 | }
|
0 commit comments