Skip to content

DefaultManagedWorkflowAndDependentResourceContext.workflowReconcileResult() throws Exception in case DRs have not been reconciled #2625

Closed
@ebma16

Description

@ebma16

Bug Report

What did you do?

When reconciling DRs with a ManagedWorkflow and utilizing the Explicit Workflow Incovation feature, there are cases where the DRs or the workflow are not reconciled. This could happen, for instance, when the current state of the CR (Custom Resource) prevents the reconciliation of the DRs.

Despite this, I need to access the context.managedWorkflowAndDependentResourceContext()?.workflowReconcileResult in my reconciler. Prior to v5, this method returned an Optional, so I could easily check for the existence of a workflowReconcileResult.

What did you expect to see?

Since v5, the context.managedWorkflowAndDependentResourceContext().workflowReconcileResult no longer returns an Optional. Instead, I expected it to return either an Object or null if no result was available.

What did you see instead? Under which circumstances?

An IllegalStateException was thrown. The Default Workflow only adds the RECONCILE_RESULT_KEY into the context when the DRs are reconciled (see here).

As a result the getMandatory() method throws an IllegalStateException because the DRs were not reconciled due to an unmet condition in the explicit workflow invocation. The RECONCILE_RESULT_KEY cannot be found in the context, causing the exception.

java.lang.IllegalStateException: Mandatory attribute (key: java.lang.Object@c9edbfc, type: io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowReconcileResult) is missing or not of the expected type
	at io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedWorkflowAndDependentResourceContext.lambda$getMandatory$0(DefaultManagedWorkflowAndDependentResourceContext.java:71) ~[operator-framework-core-5.0.0-beta1.jar:na]
	at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
	at io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedWorkflowAndDependentResourceContext.getMandatory(DefaultManagedWorkflowAndDependentResourceContext.java:70) ~[operator-framework-core-5.0.0-beta1.jar:na]
	at io.javaoperatorsdk.operator.api.reconciler.dependent.managed.DefaultManagedWorkflowAndDependentResourceContext.getWorkflowReconcileResult(DefaultManagedWorkflowAndDependentResourceContext.java:77) ~[operator-framework-core-5.0.0-beta1.jar:na]
	at io.pasx.mes.install.operator.service.genericservice.GenericServiceReconciler.getUpdatedStatus(GenericServiceReconciler.kt:414) ~[main/:na]

Environment

java-operator-sdk: 5.0.0-beta1

Additional context

Could you clarify the intended usage of the context.managedWorkflowAndDependentResourceContext()?.workflowReconcileResult in v5? Specifically, how should the workflowReconcileResult be accessed in situations like this? I would not expect to have to manually wrap this check in a try/catch block or check in advance whether the reconciliation has been explicitly triggered manually.

Best regards
Martin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions