Skip to content

Evaluate an higher level abstraction on top of the Reconcile Loop #843

Description

@andreaTP

The Reconcile Loop provides a basic building block that allows writing simple operators.

When an operator starts to perform some "more advanced" operations the logic can easily become messy, here I would like to explore what the SDK can offer to help structuring the code of more complex workflows.

To start the discussion I can put on the table an early experiment I ran to model the Reconciliation loop as a Finite State Machine:
https://github.com/andreaTP/poc-operator-mutable-jar/blob/34d65d9626b7a1202ba1a8197366f49e2f2c0aa6/src/main/java/org/keycloak/ControllerFSM.java#L16-L21

This implementation is based on an opinionated decision:

  • use (at least part of) the Status field of the CR to store the status

Running the example you can already see in action a few of the "benefits" of this approach:

  • The workflow description is extremely evident and clear
  • Easier to read (at least for me since I have done a ton of Actor programming 😛 )
  • The steps of the workflow are isolated and they can be run/be tested in isolation
  • Easy debugging: when something fails you need to debug only the current state and not the entire reconcile loop
  • A primitive but working control over state transitions

There are various additional possibilities if we decide to build on top of this foundation, such as:

  • The retry mechanism of the SDK can be configurable on each state
  • The compensation action caused by a failing state can be defined specifically for each state
  • Timeouts bound to specific states
  • Configurable automatic logging of the states and the transitions
  • ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions