Skip to content

Commit

Permalink
improve: optional workflow result (#2639)
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
  • Loading branch information
csviri authored Dec 17, 2024
1 parent 5dbb4c4 commit af31764
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
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

0 comments on commit af31764

Please sign in to comment.