Validate desired StatefulSet before deleting it on recreate (#1420) - #2071
Open
atsarevskiy wants to merge 1 commit into
Open
Validate desired StatefulSet before deleting it on recreate (#1420)#2071atsarevskiy wants to merge 1 commit into
atsarevskiy wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1420.
Problem
recreateStatefulSetdeletes 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:
ValidateCreate(ctx, statefulSet)to theIKubeSTSinterface.chi:CreateOptions.DryRun = [DryRunAll];chk: controller-runtimeclient.DryRunAll). Validation runs on the API server, nothing is persisted.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): assertsValidateCreateruns exactly once before the delete on the success path.