Skip to content

Validate desired StatefulSet before deleting it on recreate (#1420) - #2071

Open
atsarevskiy wants to merge 1 commit into
Altinity:0.27.4from
atsarevskiy:fix/1420-validate-before-recreate
Open

Validate desired StatefulSet before deleting it on recreate (#1420)#2071
atsarevskiy wants to merge 1 commit into
Altinity:0.27.4from
atsarevskiy:fix/1420-validate-before-recreate

Conversation

@atsarevskiy

Copy link
Copy Markdown

Fixes #1420.

Problem

recreateStatefulSet deletes the existing StatefulSet before creating the desired one. When the desired spec is one the API server rejects (for example an invalid label value carried in from the CR), the existing StatefulSet is already gone by the time the create is attempted, the create fails, and the reconcile aborts. The host is left with no StatefulSet and no pod until a human intervenes.

Fix

Validate the desired StatefulSet with a server-side dry-run create before touching the existing one:

  • Add ValidateCreate(ctx, statefulSet) to the IKubeSTS interface.
  • Implement it in both adapters as a dry-run create (chi: CreateOptions.DryRun = [DryRunAll]; chk: controller-runtime client.DryRunAll). Validation runs on the API server, nothing is persisted.
  • In recreateStatefulSet, dry-run the desired StatefulSet first. If the API server rejects it, log at warning level and return the error without deleting the existing StatefulSet, so the running host stays up and the next reconcile retries.

Tests

pkg/controller/common/statefulset/statefulset-reconciler_test.go:

  • TestRecreateStatefulSet_InvalidDesiredSkipsDelete (new): a dry-run rejection propagates the error and performs zero deletes and zero creates.
  • TestRecreateStatefulSet_HappyPath (updated): asserts ValidateCreate runs exactly once before the delete on the success path.

recreateStatefulSet deletes the existing StatefulSet before creating the
desired one, so a desired spec the API server rejects leaves the host
with no StatefulSet and aborts the reconcile (Altinity#1420). Dry-run the desired
StatefulSet first via a new ValidateCreate on IKubeSTS (chi and chk
adapters); if it is rejected, return without deleting the existing one.

Signed-off-by: Andrei Tcarevskii <atcarevs@amazon.com>
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.

1 participant