Skip to content

Fix ASTS ControllerRevision adoption idempotency#132

Open
fgksgf wants to merge 2 commits into
masterfrom
codex/asts-adoption-idempotent
Open

Fix ASTS ControllerRevision adoption idempotency#132
fgksgf wants to merge 2 commits into
masterfrom
codex/asts-adoption-idempotent

Conversation

@fgksgf

@fgksgf fgksgf commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

  • Make ControllerRevision adoption idempotent during native StatefulSet to AdvancedStatefulSet migration.
  • Deduplicate revisions that match both the StatefulSet selector and the upgrade marker.
  • Remove the upgrade marker after restoring selector labels so migrated revisions are not repeatedly processed.
  • Add regression coverage for mixed already-owned/orphan revisions and conflicting ownership.

Why

During ASTS migration, a reconcile can partially adopt ControllerRevisions and then retry while some revisions are already owned by the same AdvancedStatefulSet and others still carry apps.pingcap.com/upgrade-to-asts. The previous adoption path tried to adopt every listed revision again, so it failed with attempt to adopt revision owned by ... and could leave the StatefulSet status/scale path stuck.

How

  • ListRevisions still lists revisions by selector and by upgrade marker, but now returns each revision once.
  • AdoptOrphanRevisions skips revisions already owned by the same StatefulSet UID, adopts only orphan revisions, and still rejects revisions owned by another controller.
  • syncLabels deep-copies the revision, restores selector labels from the pod template, and removes the migration marker.
  • adoptOrphanRevisions syncs labels whenever marker cleanup is needed, even if there are no remaining orphan revisions.

Testing

  • git diff --check origin/master...HEAD
  • GOOS=linux GOARCH=amd64 go test -c ./pkg/controller/statefulset -o /tmp/advanced-statefulset-statefulset.test
  • go test ./pkg/controller/statefulset
  • GINKGO_NO_COLOR=y KUBE_VERSION=v1.28 KUBE_WORKERS=1 ./hack/e2e.sh
    • Local kind e2e passed on PR head 05fecf337327: 16 Passed | 0 Failed | 0 Pending | 5 Skipped in 15m35.765805677s.

Risks and Reviewer Focus

  • Review the adoption semantics around owner UID matching. Same-owner revisions are treated as already adopted; different-owner revisions still fail to avoid stealing ownership.
  • This branch is based on the v0.7.0 tag for a patch-release style fix, while the PR targets master. git merge-tree did not show conflict markers when merging into current master.

@pingcap-cla-assistant

pingcap-cla-assistant Bot commented Jul 1, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves AdvancedStatefulSet (ASTS) migration robustness by making ControllerRevision adoption and migration-marker processing idempotent, preventing repeated adoption attempts and cleaning up upgrade markers once revisions have been reconciled.

Changes:

  • Deduplicate ControllerRevisions returned from selector-based and upgrade-marker-based listing.
  • Make adoption idempotent by skipping revisions already owned by the same ASTS UID and rejecting conflicting ownership.
  • Ensure revision labels are synced via deep-copy and remove the migration marker; add regression tests for mixed owned/orphan scenarios.

Reviewed changes

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

File Description
pkg/controller/statefulset/stateful_set.go Deep-copies revisions before label mutation; removes upgrade marker; adjusts label-sync/adoption flow.
pkg/controller/statefulset/stateful_set_test.go Adds controller-level regression tests covering marker cleanup and orphan adoption behavior.
pkg/controller/statefulset/stateful_set_control.go Dedupes listed revisions and makes adoption idempotent for already-owned revisions while rejecting other owners.
pkg/controller/statefulset/stateful_set_control_test.go Adds unit tests for revision dedupe and adoption ownership semantics; adds helpers for upgrade-marker scenarios.

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

Comment thread pkg/controller/statefulset/stateful_set.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

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 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

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 4 out of 4 changed files in this pull request and generated no new comments.

Make ControllerRevision adoption idempotent during native StatefulSet to
AdvancedStatefulSet migration so partial-adoption retries no longer fail
with "attempt to adopt revision owned by ...".

- ListRevisions returns each revision once and keeps revisions that are
  orphaned, owned by this set, or still owned by the builtin StatefulSet
  being migrated (marker + apps/v1 StatefulSet owner); foreign revisions
  are filtered out.
- AdoptOrphanRevisions skips revisions already owned by this set, adopts
  only orphans, and still rejects revisions owned by another controller.
- createControllerRevision only reuses a data-equal revision when it is
  usable by this set, avoiding duplicate revisions during migration.
- truncateHistory keeps builtin migration revisions until GC orphans them;
  getStatefulSetRevisions does not bump the Revision of a builtin-owned
  migration revision on rollback.
- syncLabels deep-copies the revision, restores selector labels, and
  removes the migration marker only for orphaned/owned revisions.

Add regression coverage for mixed owned/orphan revisions, conflicting
ownership, builtin-owner migration revisions, and rollback handling.
@fgksgf fgksgf force-pushed the codex/asts-adoption-idempotent branch from 05fecf3 to 148d79e Compare July 5, 2026 01:43
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.

2 participants