Skip to content

[FSM] add result types DoneResultWithStatusCondition and DoneAndRequeueAfterCompletion[WithBackoff]#42

Merged
harveyxia merged 4 commits intomainfrom
new-result-types
May 19, 2025
Merged

[FSM] add result types DoneResultWithStatusCondition and DoneAndRequeueAfterCompletion[WithBackoff]#42
harveyxia merged 4 commits intomainfrom
new-result-types

Conversation

@harveyxia
Copy link
Copy Markdown
Collaborator

@harveyxia harveyxia commented May 15, 2025

💸 TL;DR

Adds new result types for modeling new FSM control flow scenarios: DoneResultWithStatusCondition and DoneAndRequeueAfterCompletion[WithBackoff]

Changes

  1. DoneResultWithStatusCondition allows marking a state as completed with a custom status condition status (the boolean), message, and reason.
    1. This is useful when callers want freedom to customize any of these fields (like setting the status condition to False even though it completed without error)
  2. DoneAndRequeueAfterCompletion[WithBackoff] allows the caller to requeue at the end of the FSM (i.e. after Reconcile() returns). This is useful for modeling scenarios where you want to requeue but also execute all subsequent FSM states. Edge case semantics:
    1. Subsequent states returning this result type take precedence.
    2. This result type can be pre-empted by any subsequent state returning a requeue or error result.
  3. Behavior change: The FSM reconciler now correctly sets the Ready status condition as the conjunction of all other conditions. If any conditions are failed, the Ready condition's message will include the failed status conditions.
    1. This may break existing users tests if they assert on the contents of the Ready condition

Other Notes

  1. We previously had no explicit test coverage of the result types (they were only implicitly functionally tested in the context of other tests like the envtest IT). I've added explicit table-driven tests covering all result types.
  2. To achieve 1, I had to plumb through WithSkipNameValidation to the FSM builder. There's some global state that controller-runtime tracks to prevent multiple reconcilers registering with the same name.
  3. To achieve 1, I had to add a builder method Reconciler(...) reconcile.TypedReconciler[ctrl.Request] so callers can extract the underlying controller-runtime reconciler

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

I also tested this against reddit/achilles's suite of envtests to provide confidence that the changes to the core FSM reconciler didn't break existing behavior (see here)

@harveyxia harveyxia marked this pull request as ready for review May 16, 2025 12:52
@harveyxia harveyxia requested a review from a team as a code owner May 16, 2025 12:52
Copy link
Copy Markdown
Contributor

@karanthukral karanthukral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks good but one question that I am unclear on

@harveyxia harveyxia requested a review from karanthukral May 16, 2025 15:56
Copy link
Copy Markdown
Member

@jessicayuen jessicayuen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a question for my own understanding

Copy link
Copy Markdown

@sydjryan sydjryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌 excellent, thank you!

@harveyxia harveyxia merged commit d3be499 into main May 19, 2025
1 check passed
@harveyxia harveyxia deleted the new-result-types branch May 19, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants