Skip to content

fix(controller): stop reconcile write churn; server-side apply StatefulSet and Services - #119

Open
amuraru wants to merge 2 commits into
masterfrom
refactor/controller-owned-field-convergence
Open

amuraru wants to merge 2 commits into
masterfrom
refactor/controller-owned-field-convergence

Conversation

@amuraru

@amuraru amuraru commented Nov 19, 2026 •

Copy link
Copy Markdown

1. Stop reconcile write churn and status loss

  • Drop the owner-rv StatefulSet label (every status write forced a StatefulSet write).
  • Sort AdditionalConfig keys and Ready/Unready members, so unchanged clusters render stable output.
  • Patch status only when changed; clearUpgradeStatus now writes the status subresource.
  • Optimistic-lock merge patches for defaults, finalizers, ServiceAccount, ConfigMap, PDB.

2. Server-side apply StatefulSet and Services

  • Apply rendered objects as zookeeper-operator-apply; fields owned by other managers are kept.
  • csaupgrade moves ownership from the legacy zookeeper-operator manager, so fields earlier versions rendered are removed when no longer requested. Migrating field ownership does not roll pods.

Behavior changes

  • StatefulSets and Services use create-only requests on cache misses. Existing objects must be controlled by the current CR UID, so ownerless objects (including those left by orphan deletion) are rejected instead of adopted. Explicit orphan recovery and retained PVC cleanup are tracked in Support explicit orphan recovery and cleanup of retained ZooKeeper PVCs #122.
  • spec.labels now propagates to existing Services and the StatefulSet; Service selector is enforced.
  • Manual edits to fields the operator doesn't render can now persist. Previously, SyncStatefulSet replaced the whole Pod template and SyncService replaced ports and annotations, so reconciliation reverted those edits. With server-side apply, a sidecar, environment variable, volume, or extra Service port added with kubectl edit can survive reconciliation if the operator doesn't own that field. This is intentional. If you relied on the operator to undo these edits, remove them explicitly. The operator still reconciles fields it renders.

Steady-state API cost

  • A settled reconcile still sends four server-side apply PATCH requests: one for the StatefulSet and one for each of the client, headless, and admin Services. Unchanged applies do not persist a write or change resourceVersion, but still reach the API server and can incur admission and audit work. Skipping these requests is tracked in Skip no-op server-side apply requests during settled reconciles #121.

Tests: unit + envtest (steady state settles, conflict retries, legacy adoption without rollout, legacy field removal).

@amuraru amuraru added the e2e label Nov 19, 2026
@amuraru
amuraru force-pushed the refactor/controller-owned-field-convergence branch from 1bf1457 to 7751a9b Compare November 20, 2026 14:50
@amuraru
amuraru force-pushed the refactor/controller-owned-field-convergence branch from 7751a9b to 86a181f Compare November 20, 2026 15:15
@amuraru
amuraru force-pushed the refactor/controller-owned-field-convergence branch from 86a181f to 6e41abc Compare November 20, 2026 15:42
Use deterministic rendering and optimistic patches to avoid persisting
unchanged resources. Persist upgrade status and reject stale resize
snapshots before writing ZooKeeper metadata.

Reconcile StatefulSets and Services with guarded apply and compatibility
writes. Preserve immutable settings and unrelated ownership, keep complete
sources for mounted volumes, and update Service exposure rules atomically
without replacing allocated NodePorts. Resolve conflicting legacy seccomp
annotations when applying explicit profiles.

Document ownership and RBAC prerequisites and cover convergence, migration,
and races in unit tests and an isolated shared envtest control plane.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrate the generic main field manager only when it owns the legacy
StatefulSet marker. Test logging and scheduling migration and verify
that unrelated main-owned fields remain untouched. Document a targeted
cleanup for verified legacy Service DNS annotations without claiming
arbitrary Service fields from main.
@amuraru
amuraru force-pushed the refactor/controller-owned-field-convergence branch from 722f62e to 69a735f Compare November 21, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants