Skip to content

feat(cocoonset): stamp generation onto owned pods for lifecycle bridge#4

Merged
CMGS merged 4 commits into
mainfrom
feat/lifecycle-state-annotation
May 10, 2026
Merged

feat(cocoonset): stamp generation onto owned pods for lifecycle bridge#4
CMGS merged 4 commits into
mainfrom
feat/lifecycle-state-annotation

Conversation

@tonicmuroq
Copy link
Copy Markdown
Contributor

@tonicmuroq tonicmuroq commented May 10, 2026

Summary

cocoon-operator stamps `cocoonset.cocoonstack.io/generation = cs.metadata.generation` onto every owned pod. This is the bridge that lets vk-cocoon publish a counter-based `lifecycle-observed-generation` for clients to gate completion polling on (`obs-gen >= G && state == target`).

  • `newManagedPod` sets the annotation at pod creation
  • `Reconciler.syncCocoonSetGeneration` runs near the top of every `Reconcile` and walks owned pods, short-circuiting when the annotation is already current. Generation reconciles are gated by `GenerationChangedPredicate`, so steady-state ticks only happen on actual spec changes
  • Runs before any spec-driven patch (`applySuspend`, `applyUnsuspend`, etc.) so the generation is already in place when those patches trigger `UpdatePod` on vk-cocoon

Why

Without this bridge, vk-cocoon would have no way to know which spec revision its lifecycle transitions correspond to — clients polling `lifecycle-state == 'hibernated'` cannot distinguish a fresh hibernate from a stale terminal state from a previous lifecycle. Per K8s API conventions, the canonical disambiguator is `status.observedGeneration` paired with the state — counter, not clock.

Dependencies

  • Requires cocoon-common branch `feat/lifecycle-state-annotation` — bumped via pseudo-version pinned to that PR's commit.
  • Companion PR in vk-cocoon writes the lifecycle-state triple back; without it, this annotation is set but unused.
  • Design doc in cocoon-specs PR.

Test plan

  • `go test -race ./...` passes
  • `make lint` 0 issues on `GOOS=linux` and `GOOS=darwin`
  • Wait for cocoon-common PR's CI to confirm pseudo-version resolves correctly in this PR's CI
  • e2e: hibernate-then-wake on a recently-hibernated VM; client polls and observes obs-gen advances on each transition

tonicmuroq and others added 3 commits May 10, 2026 12:15
cocoon-operator now stamps cs.metadata.generation onto every owned pod
via cocoonset.cocoonstack.io/generation. vk-cocoon reads this back as
lifecycle-observed-generation when a state transition completes,
giving clients a counter-based completion signal that is not subject
to wallclock skew.

- newManagedPod sets the annotation at pod creation
- Reconcile.syncCocoonSetGeneration walks owned pods every reconcile,
  short-circuits when the annotation is already at cs.Generation
- Runs near the top of Reconcile so the projection is in place before
  any spec-driven patch (applySuspend, etc.) fires

Bumps cocoon-common to the lifecycle-state contract commit.
PatchCocoonSetGeneration here is unaffected by the upstream rename
(operator only uses the helper signature, not the renamed
LifecycleStatus.Annotations() method).
Drop the WHAT-restating sentence on syncCocoonSetGeneration and the
short-circuit detail (an implementation note about the helper, not this
function's contract). Collapse the duplicate call-site comment in
Reconcile to a one-line WHY about placement.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a “spec generation → pod annotation” bridge for CocoonSet-owned pods so downstream components (vk-cocoon) can publish a counter-based lifecycle-observed-generation for reliable client completion gating.

Changes:

  • Stamp cocoonset.cocoonstack.io/generation onto newly created managed pods.
  • Add a reconciler step that patches the generation annotation onto all currently owned pods early in Reconcile.
  • Bump cocoon-common to a pseudo-version that provides the shared constants/helpers used for stamping.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
go.mod Bumps github.com/cocoonstack/cocoon-common to the commit that supports lifecycle generation stamping.
go.sum Updates module sums consistent with the cocoon-common bump / tidy.
cocoonset/reconciler.go Invokes generation stamping near the top of reconciliation, before spec-driven pod patches.
cocoonset/pods.go Adds generation annotation when constructing new managed pods.
cocoonset/pods_test.go Adds a unit test verifying newManagedPod stamps the generation annotation.
cocoonset/lifecycle.go Introduces syncCocoonSetGeneration to patch generation onto existing owned pods.
cocoonset/lifecycle_test.go Adds unit tests validating stamping across multiple pods and the “already current” path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cocoonset/pods.go
newManagedPod stamps the annotation, then VMSpec.Apply / ToolboxSpec.Apply
mutate annotations afterwards. Apply currently merges via
ensurePodAnnotations, but that is a contract of cocoon-common — pin the
behavior with a regression test on each build* path so a future replace
(instead of merge) implementation fails loudly here.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

@CMGS CMGS merged commit a53d670 into main May 10, 2026
6 checks passed
@CMGS CMGS deleted the feat/lifecycle-state-annotation branch May 10, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants