Skip to content
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

improve: optional workflow result #2639

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public <T> T getMandatory(Object key, Class<T> expectedType) {
}

@Override
public WorkflowReconcileResult getWorkflowReconcileResult() {
return getMandatory(RECONCILE_RESULT_KEY, WorkflowReconcileResult.class);
public Optional<WorkflowReconcileResult> getWorkflowReconcileResult() {
return get(RECONCILE_RESULT_KEY, WorkflowReconcileResult.class);
}

@Override
public WorkflowCleanupResult getWorkflowCleanupResult() {
return getMandatory(CLEANUP_RESULT_KEY, WorkflowCleanupResult.class);
public Optional<WorkflowCleanupResult> getWorkflowCleanupResult() {
return get(CLEANUP_RESULT_KEY, WorkflowCleanupResult.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public interface ManagedWorkflowAndDependentResourceContext {
@SuppressWarnings("unused")
<T> T getMandatory(Object key, Class<T> expectedType);

WorkflowReconcileResult getWorkflowReconcileResult();
Optional<WorkflowReconcileResult> getWorkflowReconcileResult();

@SuppressWarnings("unused")
WorkflowCleanupResult getWorkflowCleanupResult();
Optional<WorkflowCleanupResult> getWorkflowCleanupResult();

/**
* Explicitly reconcile the declared workflow for the associated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public UpdateControl<BulkDependentTestCustomResource> reconcile(
numberOfExecutions.incrementAndGet();

var ready = context.managedWorkflowAndDependentResourceContext().getWorkflowReconcileResult()
.orElseThrow()
.allDependentResourcesReady();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public UpdateControl<BulkDependentTestCustomResource> reconcile(

var nonReadyDependents =
context.managedWorkflowAndDependentResourceContext().getWorkflowReconcileResult()
.orElseThrow()
.getNotReadyDependents();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public UpdateControl<ComplexWorkflowCustomResource> reconcile(
ComplexWorkflowCustomResource resource,
Context<ComplexWorkflowCustomResource> context) throws Exception {
var ready = context.managedWorkflowAndDependentResourceContext().getWorkflowReconcileResult()
.orElseThrow()
.allDependentResourcesReady();

var status = Objects.requireNonNullElseGet(resource.getStatus(), ComplexWorkflowStatus::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public UpdateControl<WorkflowAllFeatureCustomResource> reconcile(
}
final var reconcileResult = context.managedWorkflowAndDependentResourceContext()
.getWorkflowReconcileResult();
final var msgFromCondition = reconcileResult.getDependentConditionResult(
final var msgFromCondition = reconcileResult.orElseThrow().getDependentConditionResult(
DependentResource.defaultNameFor(ConfigMapDependentResource.class),
Condition.Type.RECONCILE, String.class)
.orElse(ConfigMapReconcileCondition.NOT_RECONCILED_YET);
resource.getStatus()
.withReady(reconcileResult.allDependentResourcesReady())
.withReady(reconcileResult.orElseThrow().allDependentResourcesReady())
.withMsgFromCondition(msgFromCondition);
return UpdateControl.patchStatus(resource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public UpdateControl<HandleWorkflowExceptionsInReconcilerCustomResource> reconci
Context<HandleWorkflowExceptionsInReconcilerCustomResource> context) {

errorsFoundInReconcilerResult = context.managedWorkflowAndDependentResourceContext()
.getWorkflowReconcileResult().erroredDependentsExist();
.getWorkflowReconcileResult().orElseThrow().erroredDependentsExist();


return UpdateControl.noUpdate();
Expand All @@ -36,7 +36,7 @@ public DeleteControl cleanup(HandleWorkflowExceptionsInReconcilerCustomResource
Context<HandleWorkflowExceptionsInReconcilerCustomResource> context) {

errorsFoundInCleanupResult = context.managedWorkflowAndDependentResourceContext()
.getWorkflowCleanupResult().erroredDependentsExist();
.getWorkflowCleanupResult().orElseThrow().erroredDependentsExist();
return DeleteControl.defaultDelete();
}

Expand Down
Loading