Repository navigation
Description
Description
With update.strategy: Auto, the operator runs the update-compatibility job and then reads the job pod's exit codes in AutoUpdateLogic.checkUpdateType. Exit code 0 means a rolling update. Every other outcome leads to decideRecreateUpdate, and that includes outcomes where the check didn't produce a result:
- The Job is
Failedwith reasonDeadlineExceeded(kc.operator.keycloak.update-pod-deadline-seconds, default 300 s). - A container never terminated.
AutoUpdateLogic.exitCode()falls back to1when there is noterminatedstate. - The container exited with
1. Inupdate-compatibility checkthat code only comes from picocli'sexitCodeOnExecutionException(), i.e. an uncaught exception. Compatibility results are only0(ROLLING) or3(RECREATE). - The container was killed, e.g. exit
137, which lands in thedefaultbranch.
In all of these cases the operator has no compatibility result. It still takes the most disruptive path: handleRecreateUpdate scales the StatefulSet to 0 and every instance goes down.
The deadline covers sandbox creation and image pull, not only the two Keycloak starts. On a cluster with node autoscaling, the job pod can land on a fresh node and run out of time without any incompatible change. What we saw:
- Keycloak Operator 26.8.2,
Auto, 2 instances, CR change was env only. - Job created 09:05:15. Deadline reached 09:10:21. Both Keycloak pods were deleted at 09:10:20 and 09:10:24. The first pod was ready again at about 09:12:45.
- We reproduced the same outage on a test CR.
Value proposition
Auto is meant to avoid downtime for compatible changes. Today a slow node or registry is enough to cause a full outage, and the CR status only shows that a recreate happened. Users then raise the deadline and hope it holds.
Goals
- Recreate only on a real result that rules out rolling: exit
3(incompatible) and4(rolling-updatesfeature disabled). Exit2(invalid config) probably belongs here too, since a retry won't change it. - For job deadline exceeded, container not terminated, exit
1or killed: keep the current StatefulSet, set a status condition such asUpdateCheckFailedwith the reason, and retry the job with backoff. The operator already does this when the job pod is missing (AutoUpdate force recreate #48812, fix: updating the auto logic if the pod cannot be found #49030). - Optional: a setting to keep today's behavior, e.g.
spec.update.onCheckFailure: Recreate | Retry.
Non-Goals
- Changing what happens when the check reports incompatible changes.
- Changing
ExplicitorRecreateOnImageChange.
Discussion
- Endless retries could block an update. A retry limit, after which the operator stops and reports instead of recreating, seems safer to us than an outage.
Notes
Related: #48812 (recreate after the job pod went missing, about 15 min outage), #49030 (its fix).
Metadata
Metadata
Assignees
Labels
Type
Fields
Value
Effort
Votes
Projects
- StatusShow more project fieldsOpen< 3BF0 /span>
Activity
fma-xx commentedon Nov 20, 2026
A correction to the description:
activeDeadlineSecondsis set on the pod spec of the update job (KeycloakUpdateJobDependentResource#createPodSpec). So the pod fails with reasonDeadlineExceeded, and withbackoffLimit: 0the Job ends asFailedwith reasonBackoffLimitExceeded. The effect is the same, but that points to a fix that mostly uses the Job controller.Proposal, which keeps today's behavior by default:
New operator setting, e.g.
kc.operator.keycloak.update-job-retries, default0.desired()uses it forbackoffLimitinstead ofJOB_RETRIES.When retries are > 0, add a
podFailurePolicythat fails the Job right away on real results, so only "no result" outcomes are retried:The Job controller only matches containers that terminated with a non-zero code, init containers included. A pod that hit the deadline, never pulled its image or was killed falls to the default
Countand gets a new pod after the usual 10s/20s/40s backoff, with a fresh deadline.restartPolicy: Neveris already set.podFailurePolicyis GA since Kubernetes 1.31.AutoUpdateLogicneeds no new branch.isJobRunningalready waits for theComplete/Failedcondition, so the current StatefulSet stays as it is during retries. Once retries are used up, the logic is the same as today and still recreates.findPodForJobreturns the first pod of the list. With retries the Job can have several pods, so it has to pick the newest one.With the default of
0,testImageChangeandtestNoJobReusekeep passing unchanged. I'd add a unit test fordesired()and anUpdateTestcase with retries set to 1 and a job pod that fails once.Would you accept a PR along these lines? If you'd rather have this on the CR (e.g.
spec.update), or change the default so the operator stops and reports instead of recreating, I can do it that way instead.shawkins commentedon Nov 23, 2026
#48812 was a related fix. I would be fine with a more aggressive code change this time around - as you are describing only do rolling on the exit codes that are known results from the command.
In all other circumstances it seems like we need a status update and to retry the job. Whether this is done via the podFailurePolicy or via the KeycloakController/KeycloakUpdateJobDependentResource should be based upon what looks like the cleanest implementation. I don't mind if the behavior is to simply keep retrying indefinitely - the KeycloakController already polls / retries on failures.
fma-xx commentedon Nov 23, 2026
Thanks. I'll do it in the controller like #49030 first: on any outcome that isn't a result, keep the StatefulSet, delete the Job, put the reason in the status and retry with backoff. Exit 0 rolls, 3 and 4 recreate as today.
What was the exit 4 for?
shawkins commentedon Nov 23, 2026
Should be rolling-updates feature disabled.
Retry the update job when the compatibility check has no result
Retry the update job when the compatibility check has no result
Retry the update job when the compatibility check has no result
stianst commentedon Nov 27, 2026
It's not immediately clear to me if this is an enhancement or bug; please check the type if it is a bug
Select update job containers by name and keep the generation unobserved
fma-xx commentedon Nov 27, 2026
I'd keep it as an enhancement. Recreating when the check fails was the intended behavior, and this changes it: a broken image or config now blocks the update instead of recreating. That's also why it has an upgrade note for 27.0.0.
Delete the update job before recreating without instances
Retry the update job when the compatibility check has no result
Select update job containers by name and keep the generation unobserved
Delete the update job before recreating without instances