Repository navigation
Conversation
With the Auto update strategy, only the results of the update-compatibility commands decide the update type: exit code 0 rolls, 3 and 4 recreate. Any other outcome, like an exceeded deadline, a killed container or a failed command, keeps the current StatefulSet, reports a warning in the HasErrors condition and replaces the job 5 minutes after it finished. When the current or desired StatefulSet has no instances, the check is skipped and a recreate update is used, so a pending retry does not block scaling to zero. While a recreate update scales down, its original reason is kept. Closes keycloak#55401 Signed-off-by: Florian Mayer <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The compatibility check can retry indefinitely by reading the wrong init-container result, and a blocked StatefulSet update can incorrectly mark the current generation as observed.
2 open issues
What changed in this PR
This PR makes the Operator’s Auto update strategy retry compatibility checks that produce no result, preserving the running Keycloak deployment instead of causing an unnecessary recreate.
Changes:
- Adds five-minute retries for inconclusive checks and bypasses checks when scaling to or from zero instances.
- Reports retry warnings while preserving the previously observed generation.
- Adds test coverage and documents the behavior change and recovery options.
| File | Description |
|---|---|
operator/src/test/java/org/keycloak/operator/update/impl/AutoUpdateLogicTest.java |
Tests exit-code mapping, retry delays, and zero-instance handling. |
operator/src/test/java/org/keycloak/operator/testsuite/integration/UpdateTest.java |
Checks deployment preservation and incompatible-change recreates. |
operator/src/main/java/org/keycloak/operator/update/UpdateLogic.java |
Adds a hook for status updates during interrupted reconciliation. |
operator/src/main/java/org/keycloak/operator/update/impl/BaseUpdateLogic.java |
Tracks retries and adds status warnings. |
operator/src/main/java/org/keycloak/operator/update/impl/AutoUpdateLogic.java |
Implements retry decisions, delays, diagnostics, and zero-instance handling. |
operator/src/main/java/org/keycloak/operator/controllers/KeycloakUpdateJobDependentResource.java |
Exposes the Job lifetime constant for validation in tests. |
operator/src/main/java/org/keycloak/operator/controllers/KeycloakController.java |
Patches retry status while preserving rescheduling. |
docs/guides/operator/rolling-updates.adoc |
Explains retry behavior and recovery options. |
docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc |
Documents the upgrade impact of inconclusive checks blocking updates. |
Review effort: Balanced
The update job keeps init containers of the pod template, so the 'actual' and 'desired' containers are selected by name. A retry without a previous status no longer marks the current generation as observed. Closes keycloak#55401 Signed-off-by: Florian Mayer <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A cached rolling-check Job can retain a stale success across a zero-replica update and incorrectly authorize a later rolling update between different versions.
1 open issue
2 resolved since last review
Review effort: Balanced
Comment on lines
+91
to
97
| if (hasNoInstances(ContextUtils.getCurrentStatefulSet(context).orElse(null), ContextUtils.getDesiredStatefulSet(context))) { | ||
| // no instances to keep available, and a pending update without a check result must not block scaling to zero. | ||
| decideRecreateUpdate(noInstancesReason(ContextUtils.getCurrentStatefulSet(context).orElse(null))); | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| var existingJob = context.getSecondaryResource(Job.class); |
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.


Closes #55401
The update type is now decided only by exit codes that the update-compatibility commands return as a result: 0 rolls, 3 and 4 recreate. For anything else (exit 1 or 2, a killed container, an exceeded deadline, a container that never finished), the operator keeps the current StatefulSet and retries the update job, as discussed in the issue.
Some choices you may want to check:
PropertyException), so the new pods would fail to start too, and a recreate would take down all instances. The reason is reported inHasErrors. If you prefer to recreate on exit 2, it is a one-line change.HasErrorscondition. The status is written without advancingobservedGeneration, since the current generation has not been applied yet, and it is only patched when it changes. It still runs the usual status checks, so validation errors of the new spec show up under the oldobservedGeneration, which seemed more useful than hiding them. A side effect is that tools waiting for the new generation can't tie the retry warning to their change.UpdateTestcleanup timed out while scaling down a CR with a broken image. With no instances there is no availability to keep, so the check has nothing to decide. An update job that is already running when the CR is scaled to 0 runs until its deadline. A recreate also scales the StatefulSet to 0 first, so the shortcut keeps the reason of that recreate until it is finished.RecreateOnImageChangeorExplicit. Should a failure of the init container keep the old recreate behavior instead?reconcileManagedWorkflow(), which runs after the update logic interrupts, and running the workflow during a retry would also reconcile the StatefulSet. The warning is back after the next full reconciliation.I tested this on a single-node cluster with the operator running locally and a 1 minute retry delay at the time. With a 15s deadline the job was retried four times and the pods were left alone. After raising the deadline, the operator did a rolling update. An invalid option value (exit 2) was retried too.
AutoUpdateLogicTestcovers the exit code mapping and the retry delay.UpdateTest#testImageChangeused to expect a recreate for a non-existing image and now expects the retry warning and an unchanged StatefulSet. The newUpdateTest#testIncompatibleChangecovers an Auto recreate (exit 3) and checks that its reason is kept. Both pass on that cluster inlocalmode.The rolling update guide and the 27.0.0 upgrade notes describe the new behavior, since a broken image or configuration now blocks the update instead of recreating.
The change and tests were written with the help of an AI agent (Claude) and reviewed by me.