-
Notifications
You must be signed in to change notification settings - Fork 56
feat(docs): update architecture and state machines documentation #938
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
22b6776
e8f9f99
0984d8b
f2c9f56
8b9f22e
b1327b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
nlevee marked this conversation as resolved.
Outdated
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # CRD State Machines | ||
|
|
||
| Each Burrito custom resource is driven by a state machine implemented in its | ||
| reconciler (`internal/controllers/<crd>/states.go`). Burrito controllers are | ||
| **level-based**: on every reconcile the controller *recomputes* the current state | ||
| from a set of boolean conditions through an ordered `switch`. There are no stored | ||
| transitions — a state's handler performs a side-effect (creating a `TerraformRun`, | ||
| a runner pod, an annotation…), and the *next* reconcile observes the changed | ||
| conditions and yields the next state. | ||
|
|
||
| A practical consequence: some states are **transient triggers**. For example a | ||
| `TerraformLayer` in `PlanNeeded` creates a run and, on the following reconcile, | ||
| is seen as running and reported as `Idle` again. | ||
|
|
||
| ## TerraformRepository | ||
|
|
||
| The repository controller keeps Git bundles in the datastore in sync with the | ||
| remote. It has two states, decided by whether the last sync is too old or failed. | ||
|
|
||
| - `Synced` — bundles are up to date; requeue at the repository sync interval. | ||
| - `SyncNeeded` — fetch latest revisions per branch, store bundles, and annotate | ||
| the affected layers. | ||
|
|
||
| ```mermaid | ||
| stateDiagram-v2 | ||
| [*] --> Synced | ||
| Synced --> SyncNeeded: last sync too old / last sync failed | ||
| SyncNeeded --> Synced: all branches synced successfully | ||
| SyncNeeded --> SyncNeeded: sync error (requeue) | ||
| ``` | ||
|
|
||
| ## TerraformLayer | ||
|
|
||
| The layer controller watches declared layers and creates `TerraformRun` resources | ||
| to plan (drift detection) and, when auto-apply is enabled, to apply. The state is | ||
| computed from conditions such as *is a run in flight*, *is a sync scheduled*, *is | ||
| the last plan too old*, *is the last relevant commit planned*, *is the apply up to | ||
| date*, and *has the last run reached its retry limit*. | ||
|
|
||
| Because the first `switch` case is "a run is in flight → `Idle`", a layer with a | ||
| running plan/apply is reported as `Idle`. `PlanNeeded` and `ApplyNeeded` are | ||
| transient: their handler creates the run and the next reconcile returns to `Idle`. | ||
|
|
||
| - `Idle` — nothing to do; requeue at the drift-detection interval. | ||
| - `PlanNeeded` — create a plan `TerraformRun`. | ||
| - `ApplyNeeded` — create an apply `TerraformRun` (only if auto-apply is enabled). | ||
| - `MaxRetriesReached` — the last run exhausted its retries; manual intervention | ||
| needed. | ||
|
|
||
| ```mermaid | ||
| stateDiagram-v2 | ||
| [*] --> Idle | ||
| Idle --> PlanNeeded: plan outdated / new relevant commit / sync scheduled | ||
| Idle --> ApplyNeeded: plan up to date but apply needed (autoApply on) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if I'm not wrong, Idle --> ApplyNeeded is not possible 🤔 The layer should transition from PlanNeeded to ApplyNeeded if the plan contains a drift. Do you confirm? |
||
| PlanNeeded --> Idle: TerraformRun (plan) created — run in flight | ||
| ApplyNeeded --> Idle: TerraformRun (apply) created — run in flight | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If i'm not wrong, these conditions are not possible, the layer stays in PlanNeeded when a plan is running, and ApplyNeeded when a apply is running |
||
| Idle --> MaxRetriesReached: last run exhausted its retries | ||
| MaxRetriesReached --> Idle: new relevant commit / retry window reset | ||
| ``` | ||
|
|
||
| ## TerraformRun | ||
|
|
||
| The run controller executes a plan or apply by creating runner pods, and handles | ||
| retries with an exponential backoff grace period. `Succeeded` and `Failed` are | ||
| terminal. | ||
|
|
||
| - `Initial` — freshly created; sets the lease and launches the first runner pod. | ||
| - `Running` — a runner pod is currently running. | ||
| - `FailureGracePeriod` — the runner failed; wait (exponential backoff) before retry. | ||
| - `Retrying` — grace period elapsed and retry limit not reached; launch a new pod. | ||
| - `Succeeded` — the runner pod exited successfully (lease released). | ||
| - `Failed` — retries exhausted (lease released). | ||
|
|
||
| ```mermaid | ||
| stateDiagram-v2 | ||
| [*] --> Initial | ||
| Initial --> Running: runner pod created | ||
| Running --> Succeeded: pod exited successfully | ||
| Running --> FailureGracePeriod: pod failed, retry limit not reached | ||
| FailureGracePeriod --> Retrying: grace period elapsed | ||
| FailureGracePeriod --> Failed: retry limit reached | ||
| Retrying --> Running: retry pod created | ||
| Succeeded --> [*] | ||
| Failed --> [*] | ||
| ``` | ||
|
|
||
| ## TerraformPullRequest | ||
|
|
||
| The pull-request controller discovers layers affected by a PR/MR, waits for their | ||
| plans, and posts a comment. Note that "comment up to date" is checked before | ||
| "layers still planning", so a PR with an up-to-date comment is reported as `Idle`. | ||
|
|
||
| - `DiscoveryNeeded` — a new commit was detected; (re)create the temporary layers | ||
| affected by the PR. | ||
| - `Planning` — the temporary layers are still planning. | ||
| - `CommentNeeded` — plans finished; post/update the PR comment. | ||
| - `Idle` — comment is up to date; nothing to do. | ||
|
|
||
| ```mermaid | ||
| stateDiagram-v2 | ||
| [*] --> DiscoveryNeeded | ||
| DiscoveryNeeded --> Planning: temp layers created, commit discovered | ||
| Planning --> CommentNeeded: all layers finished planning | ||
| CommentNeeded --> Idle: comment posted on PR/MR | ||
| Idle --> DiscoveryNeeded: new commit on the PR branch | ||
| ``` | ||
|
|
||
| ## How the CRDs interact | ||
|
|
||
| The resources form a chain: the repository annotates layers with the latest | ||
| relevant commit, layers create runs, runs create runner pods, and pods write plan | ||
| and apply results back onto the layer's annotations. A pull request creates | ||
| temporary layers and reports their plan results as a comment. | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| Repo[TerraformRepository] -->|annotates last relevant commit| Layer[TerraformLayer] | ||
| Layer -->|creates on plan/apply needed| Run[TerraformRun] | ||
| Run -->|creates runner| Pod[Runner Pod] | ||
| Pod -->|updates plan/apply annotations| Layer | ||
| PR[TerraformPullRequest] -->|creates temp layers| Layer | ||
| PR -->|reads plan results, comments| Git[Git provider] | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| babel==2.18.0 | ||
| backrefs==7.0 | ||
| beautifulsoup4==4.15.0 | ||
| certifi==2026.6.17 | ||
| charset-normalizer==3.4.9 | ||
| click==8.4.2 | ||
| colorama==0.4.6 | ||
| editorconfig==0.17.1 | ||
| ghp-import==2.1.0 | ||
| idna==3.18 | ||
| jinja2==3.1.6 | ||
| jsbeautifier==2.0.3 | ||
| markdown==3.10.2 | ||
| markupsafe==3.0.3 | ||
| mergedeep==1.3.4 | ||
| mike==2.2.0 | ||
| mkdocs==1.6.1 | ||
| mkdocs-get-deps==0.2.2 | ||
| mkdocs-material==9.7.6 | ||
| mkdocs-material-extensions==1.3.1 | ||
| mkdocs-mermaid2-plugin==1.2.3 | ||
| packaging==26.2 | ||
| paginate==0.5.7 | ||
| pathspec==1.1.1 | ||
| platformdirs==4.10.0 | ||
| pygments==2.20.0 | ||
| pymdown-extensions==11.0.1 | ||
| pyparsing==3.3.2 | ||
| python-dateutil==2.9.0.post0 | ||
| pyyaml==6.0.3 | ||
| pyyaml-env-tag==1.1 | ||
| requests==2.34.2 | ||
| setuptools==83.0.0 | ||
| six==1.17.0 | ||
| soupsieve==2.8.4 | ||
| typing-extensions==4.16.0 | ||
| urllib3==2.7.0 | ||
| verspec==0.1.0 | ||
| watchdog==6.0.0 |
Uh oh!
There was an error while loading. Please reload this page.