-
Notifications
You must be signed in to change notification settings - Fork 218
fix: managed workflow result is available even when exception is thrown #2552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import io.javaoperatorsdk.operator.api.reconciler.dependent.Deleter; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.GarbageCollected; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedDependentResourceContext; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; | ||
|
||
/** | ||
|
@@ -79,7 +80,7 @@ private Map<String, DependentResourceNode> toMap(Set<DependentResourceNode> node | |
} | ||
map.put(node.getName(), node); | ||
} | ||
if (topLevelResources.size() == 0) { | ||
if (topLevelResources.isEmpty()) { | ||
throw new IllegalStateException( | ||
"No top-level dependent resources found. This might indicate a cyclic Set of DependentResourceNode has been provided."); | ||
} | ||
|
@@ -91,6 +92,8 @@ public WorkflowReconcileResult reconcile(P primary, Context<P> context) { | |
WorkflowReconcileExecutor<P> workflowReconcileExecutor = | ||
new WorkflowReconcileExecutor<>(this, primary, context); | ||
var result = workflowReconcileExecutor.reconcile(); | ||
context.managedDependentResourceContext() | ||
.put(DefaultManagedDependentResourceContext.RECONCILE_RESULT_KEY, result); | ||
if (throwExceptionAutomatically) { | ||
result.throwAggregateExceptionIfErrorsPresent(); | ||
} | ||
|
@@ -102,6 +105,8 @@ public WorkflowCleanupResult cleanup(P primary, Context<P> context) { | |
WorkflowCleanupExecutor<P> workflowCleanupExecutor = | ||
new WorkflowCleanupExecutor<>(this, primary, context); | ||
var result = workflowCleanupExecutor.cleanup(); | ||
context.managedDependentResourceContext() | ||
.put(DefaultManagedDependentResourceContext.CLEANUP_RESULT_KEY, result); | ||
if (throwExceptionAutomatically) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't rather only this throw removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's slightly different in v5 but the problem is still present in a somewhat different form, though. |
||
result.throwAggregateExceptionIfErrorsPresent(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should solve this this way (with the context map), only if there is no other way around this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's not super nice but the current way is not great either (casting to the implementation, which is not a given, especially during tests since it breaks with mocks). I actually had a different implementation initially but I would like to remove the reliance on a specific implementation and a cast to it because I don't think it's a nice design.