Skip to content

Commit 13ef6fb

Browse files
authored
fix(operator): Scale statefulset to 0 to prepare for update (#30450)
When performing a keycloak update, the operator is supposed to make sure that potential database migrations are run with only one pod active. This change makes the operator scale down the stateful set to zero pods in preparation for the update. The next reconciliation loop will scale the stateful set back up and change the image, making sure migrations are being run on the first pod that is brought up. This also makes sure that the rollover works even if the infinispan versions are incompatible. (ref: #30449) Signed-off-by: Schmidt, Sascha (sasschmidt) <[email protected]>
1 parent 333f1fb commit 13ef6fb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,13 @@ public void migrateDeployment(StatefulSet previousDeployment, StatefulSet reconc
461461
var reconciledContainer = reconciledDeployment.getSpec().getTemplate().getSpec().getContainers().get(0);
462462

463463
if (!previousContainer.getImage().equals(reconciledContainer.getImage())
464-
&& previousDeployment.getStatus().getReplicas() > 1) {
464+
&& previousDeployment.getStatus().getReplicas() > 0) {
465465
// TODO Check if migration is really needed (e.g. based on actual KC version); https://github.com/keycloak/keycloak/issues/10441
466466
Log.info("Detected changed Keycloak image, assuming Keycloak upgrade. Scaling down the deployment to one instance to perform a safe database migration");
467467
Log.infof("original image: %s; new image: %s", previousContainer.getImage(), reconciledContainer.getImage());
468468

469469
reconciledContainer.setImage(previousContainer.getImage());
470-
reconciledDeployment.getSpec().setReplicas(1);
470+
reconciledDeployment.getSpec().setReplicas(0);
471471

472472
reconciledDeployment.getMetadata().getAnnotations().put(Constants.KEYCLOAK_MIGRATING_ANNOTATION, Boolean.TRUE.toString());
473473
}

0 commit comments

Comments
 (0)