Skip to content

Add StateMachineVersion resource - #104

Open
bjorn-stange-expel wants to merge 5 commits into
aws-controllers-k8s:mainfrom
bjorn-stange-expel:add-statemachineversion
Open

bjorn-stange-expel wants to merge 5 commits into
aws-controllers-k8s:mainfrom
bjorn-stange-expel:add-statemachineversion

Conversation

@bjorn-stange-expel

@bjorn-stange-expel bjorn-stange-expel commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Addresses aws-controllers-k8s/community#2797

Adds a StateMachineVersion resource for publishing immutable point-in-time snapshots of state machines.

  • Create: PublishStateMachineVersion
  • Read: custom hook calling DescribeStateMachine with the version ARN (no dedicated describe API exists)
  • Update: terminal error — versions are immutable in the AWS API, so all spec fields are is_immutable (also enforced via CRD x-kubernetes-validations)
  • Delete: DeleteStateMachineVersion
  • stateMachineRef resolves the parent StateMachine ARN

Only hooks.go is hand-written; everything else is generated with code-generator v0.60.0 (branch is rebased on main after #115). Follows the Lambda controller's Version pattern.

Test plan

  • go build ./... passes
  • E2E: test_state_machine_version.py — 3/3 passed (create/delete, custom find + out-of-band delete, immutable-update-rejected)

🤖 Generated with Claude Code

@ack-prow ack-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2026
@ack-prow
ack-prow Bot requested review from a-hilaly and michaelhtm March 1, 2026 02:50
@ack-prow ack-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 1, 2026
@ack-prow

ack-prow Bot commented Mar 1, 2026

Copy link
Copy Markdown

Hi @bjorn-stange-expel. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@bjorn-stange-expel bjorn-stange-expel changed the title ADHOC: Add StateMachineVersion resource Add StateMachineVersion resource Mar 1, 2026
@bjorn-stange-expel
bjorn-stange-expel marked this pull request as ready for review March 1, 2026 03:35
@ack-prow ack-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2026
@ack-prow
ack-prow Bot requested a review from knottnt March 1, 2026 03:35
@a-hilaly

a-hilaly commented Mar 4, 2026

Copy link
Copy Markdown
Member

/test all

@bjorn-stange-expel
bjorn-stange-expel marked this pull request as draft July 2, 2026 15:59
@ack-prow ack-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 2, 2026
@bjorn-stange-expel
bjorn-stange-expel force-pushed the add-statemachineversion branch from 2d0963e to a85d727 Compare July 2, 2026 15:59
@ack-prow

ack-prow Bot commented Jul 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bjorn-stange-expel
Once this PR has been reviewed and has the lgtm label, please assign gustavodiaz7722 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

bjorn-stange-expel and others added 2 commits July 2, 2026 13:14
Add StateMachineVersion CRD for managing immutable point-in-time snapshots
of state machines via PublishStateMachineVersion. Uses custom hooks for find
(DescribeStateMachine with the version ARN) and update (terminal error since
versions are immutable). Supports a stateMachineRef K8s reference.

Regenerated against code-generator v0.59.1 (commit 2970ca9) and controller-gen
v0.19.0 to match current upstream main, and moved generator config into the
root generator.yaml per review feedback on aws-controllers-k8s#103. The e2e create test now
asserts the resource reaches ACK.ResourceSynced=True.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rebased onto upstream main (runtime/code-generator v0.60.0). The
regenerated references.go now resolves the StateMachine reference via
the cross-namespace helper introduced in code-generator v0.60.0,
consistent with the other resources on main.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bjorn-stange-expel
bjorn-stange-expel force-pushed the add-statemachineversion branch from a85d727 to 9f841fc Compare July 2, 2026 17:17
@bjorn-stange-expel
bjorn-stange-expel marked this pull request as ready for review July 2, 2026 20:29
@ack-prow ack-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 2, 2026
@ack-prow
ack-prow Bot requested review from gustavodiaz7722 and jlbutler July 2, 2026 20:29
bjorn-stange-expel and others added 3 commits July 6, 2026 11:07
There is no DescribeStateMachineVersion API, so the controller reads
versions via DescribeStateMachine with the version ARN through a custom
hook. Cover both branches: the successful read that syncs the CR, and
the StateMachineDoesNotExist-to-NotFound mapping that lets a CR be
deleted cleanly after the version is removed out-of-band.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shabbskagalwala

Copy link
Copy Markdown

@jlbutler @a-hilaly can this be looked at again please?

@michaelhtm michaelhtm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @bjorn-stange-expel
the changes lgtm. One question I have is, Would it make sense to manage StateMachineVersions using the StateMachine resource?
Maybe using this Publish field?
/test all

@ack-prow

ack-prow Bot commented Aug 4, 2026

Copy link
Copy Markdown

@bjorn-stange-expel: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
sfn-verify-code-gen 1095bd1 link true /test sfn-verify-code-gen

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@gustavodiaz7722

Copy link
Copy Markdown
Member

@shabbskagalwala Do we have any thoughts on using the existing Publish field to manage state machine versions? I put together an alternate implementation that doesn't create a new CRD #122

@shabbskagalwala

Copy link
Copy Markdown

@shabbskagalwala Do we have any thoughts on using the existing Publish field to manage state machine versions? I put together an alternate implementation that doesn't create a new CRD #122

@gustavodiaz7722 thank you! I think this should work and your explanation on the PR #122 helps explain this choice as well

ack-prow Bot pushed a commit that referenced this pull request Sep 11, 2026
Adds `spec.publish` so a StateMachine can cut immutable versions. `CreateStateMachineInput.Publish` and `CreateStateMachineOutput.StateMachineVersionArn` were both in the ignore list, so there was no way to opt into versioning and no way to learn a version's ARN once one existed.

| Field | Purpose |
|---|---|
| `spec.publish` | Cut a version whenever configuration is pushed to AWS |
| `status.stateMachineVersionARN` | The version holding the configuration last pushed |
| `status.revisionID` | Which revision is currently live (from `DescribeStateMachine`) |

### Behaviour

Publishing is a parameter of Create/Update rather than a separate call, so a version is cut whenever the update payload differs from the current revision. `PublishStateMachineVersion` is idempotent per revision, so repeat reconciles of an unchanged spec cut nothing.

`publish` is excluded from the generated comparison: it modifies a request, it is not state of the state machine, so its value changing is not by itself a reason to call Update.

That leaves one case the comparison cannot see — turning `publish` on for an already-settled state machine produces no spec difference. `status.stateMachineVersionARN` carries that signal, since a nil ARN under `publish: true` means no version holds the configuration last pushed. The read path clears the ARN when the version it names is gone, and `customPreCompare` turns a nil ARN into a `Spec.Publish` delta, registered under a `Spec` path because the runtime only calls Update when `delta.DifferentAt("Spec")` holds. One condition covers both a state machine that has never published and one whose version was deleted out of band. The probe is confined to `clearDeletedVersionARN`, clears only on `StateMachineDoesNotExist`, and is skipped when `publish` is false.

### Why a field rather than a StateMachineVersion resource

#104 proposes the resource shape, and it is worth discussing these side by side rather than one in place of the other. Two reasons I went this way:

- **Publishing stays atomic with the content.** The version is cut by the same `UpdateStateMachine` call that sets the definition, so it cannot hold a different revision. A separate CR publishes whatever revision is current when it reconciles, and ACK gives no ordering guarantee between independent CRs.
- **No manifest accumulation.** Versions are immutable, so a per-version CR means a new, uneditable object per release, with the count tracking the 1000-version cap.

CloudFormation's `AWS::StepFunctions::StateMachineVersion` avoids both, but only because every property is `Update requires: Replacement` — one template block, replaced each deploy, which both sequences the publish and cleans up the old version. ACK has no replacement primitive, so that mechanism does not port.

### Known gap

No retention. Versions accumulate and AWS caps them at 1000 with manual deletion, so this wants a follow-up such as `keepLastVersions` on the parent. Flagging rather than hiding it.

### Testing

E2E in `test/e2e/tests/test_state_machine.py` covers publish at create, publish absent, a definition change cutting exactly one further version, enabling `publish` on an already-settled state machine, and republishing after a version is deleted outside ACK. Each case then forces a reconcile and asserts nothing further is published, since the failure mode of a delta that never settles is publishing on every pass. The nudge patches `spec.tags`: ACK filters events with `GenerationChangedPredicate` so an annotation is never delivered, and a tags-only delta short-circuits before `UpdateStateMachine` so it cannot publish by itself.

Confirmed against the live API: publish is idempotent per revision; an update with an identical payload and `publish: true` does publish when no version exists for the current revision; a missing version returns `StateMachineDoesNotExist`; version numbers are never reused after deletion.

`versionDescription` is left out deliberately — it participates in the revision fingerprint but is unreadable from the state machine, so it needs its own comparison story.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
@gustavodiaz7722

Copy link
Copy Markdown
Member

@shabbskagalwala We've merged release 1.7.0 that supports new Publish field #123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants