Skip to content

Custom Invocation of Managed Workflows #1898

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

Closed
csviri opened this issue May 11, 2023 · 6 comments · Fixed by #2274 or #2289
Closed

Custom Invocation of Managed Workflows #1898

csviri opened this issue May 11, 2023 · 6 comments · Fixed by #2274 or #2289

Comments

@csviri
Copy link
Collaborator

csviri commented May 11, 2023

In some use cases it would handy to implement custom code before the managed workflows executes, see for example:
#1896

Currently the managed workflow always execute before the reconcile(...) method automatically. What we could provide is a method invoke the managed workflow:

 public UpdateControl<MyCustomResource> reconcile(MyCustomResource primary, Context<MyCustomResource> context) {
    simulateErrorIfRequested(webPage);
   
    // custom code before workflow execution

    context.managedDependentResourceContext().invokeWorkflow();
   
   // custom code after workflow execution
    
    return UpdateControl.patchStatus(primary);
  }

Probably would be nicer to do this just in some cases, so NOT require explicit invocation by default.

So such a feature flag could look like:

@ControllerConfiguration(
    workflow = @Workflow( 
          explicitInvocation = true,
          dependents = {
              @Dependent(...),
              @Dependent(...)}
    )
public class MyCustomResourceReconciler { }

see also related issue about naming: #1773

@metacosm
Copy link
Collaborator

Would it make sense to have pre- and post-reconcile workflows that would get executed before and after calling the main reconciler method, respectively?

@csviri
Copy link
Collaborator Author

csviri commented Jan 25, 2024

Not sure how the user would then update the status, based on the results of the flow after the second workflow. Was thinking on other variants also, like having a list of managed workflows.

But would not complicate it, there are still standalone workflows for complex use cases. And usually I guess users have a set of resources they want to reconcile, with custom invocation we give possibility to check the precondition / pre-processing and set the status after, this is both general and powerful enough.

@csviri
Copy link
Collaborator Author

csviri commented Jan 31, 2024

Typically this would be useful also to set some default values as discussed here:
https://discordapp.com/channels/723455000604573736/723455000604573739/1201920896080543824

@csviri
Copy link
Collaborator Author

csviri commented Feb 5, 2024

Note that this is little bit more cumbersome for cleanup, if Cleaner interface is not implemented probably should be called implicitly even the flag is there (when not all dependents are garbage collected), if cleaner is implemented it should be called explicitly when the flag is on.

@jcechace
Copy link
Contributor

What about making the @Workflow annotation a top level and directly appleid to the Reconciler?

IMHO this would improve readability as personally I'm not a fun of overusing nested annotations.

@csviri
Copy link
Collaborator Author

csviri commented Mar 13, 2024

I wonder if this is not misleading.

context.managedDependentResourceContext().invokeWorkflow();

Maybe should be:
context.managedWorkflowContext().invokeWorkflow()

@csviri csviri closed this as completed Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment