NokiaTube | New address | Mode Phone | On high quality
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,15 @@ A deleted client is registered again from its client metadata document on its ne

A new index over the table `USER_ATTRIBUTE` has been added to increase the performance for lowercase search queries.

=== Operator retries the update compatibility check without a result
// https://github.com/keycloak/keycloak/issues/55401

With the `Auto` update strategy, the {project_name} Operator previously used a recreate update whenever the update compatibility Job did not return a rolling or recreate result, for example when the Job reached its deadline or the new image could not be pulled.
It now keeps the current StatefulSet, reports the reason as a warning in the `HasErrors` condition, and replaces the Job with a new one 5 minutes after it finished.
As a consequence, a broken image or configuration no longer takes down all instances, but blocks the update until a check returns a result, for example after the Keycloak CR is fixed.
If the check fails for the currently deployed image or configuration, for example for an image older than 26.2, scale the Keycloak CR to 0 instances or switch to the `RecreateOnImageChange` or `Explicit` update strategy to apply the update.
Scaling the Keycloak CR to 0 instances is still possible, as the Operator uses a recreate update without a Job in this case.

// ------------------------ Deprecated features ------------------------ //
== Deprecated features

Expand Down
8 changes: 8 additions & 0 deletions docs/guides/operator/rolling-updates.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ When using the `Auto` update strategy, the {project_name} Operator automatically
Read more about the process in the <@links.server id="update-compatibility"/> {section}.
This process consumes cluster resources for the time of the check and introduces a slight delay before the StatefulSet update begins.

If the Job does not produce a result, for example because it reaches its deadline, its Pod is killed, or the check command fails, the {project_name} Operator keeps the current StatefulSet.
It reports the reason as a warning in the `HasErrors` condition and replaces the Job with a new one 5 minutes after it finished, until a check produces a result.
If the current or the desired number of instances is 0, the {project_name} Operator does not start a Job and uses a recreate update, as there are no instances to keep available.

The Job also runs the update compatibility metadata command with the currently deployed image and configuration.
If this command fails, for example because the current image is older than {project_name} 26.2 or a Secret of the current configuration is missing, changing the Keycloak CR does not resolve it.
To apply the update in this case, scale the Keycloak CR to 0 instances, or switch to the `RecreateOnImageChange` or `Explicit` update strategy.

[WARNING]
====
If the Keycloak CR configured a `podTemplate` as part of the `unsupported` configuration parameters, the Keycloak Operator will do its best to use those settings for the started Job. Still it might miss some settings due to the flexibility of the `podTemplate` feature and its unsupported nature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.keycloak.operator.crds.v2beta1.deployment.KeycloakStatusAggregator;
import org.keycloak.operator.crds.v2beta1.deployment.spec.HostnameSpec;
import org.keycloak.operator.crds.v2beta1.deployment.spec.HostnameSpecBuilder;
import org.keycloak.operator.update.UpdateLogic;
import org.keycloak.operator.update.UpdateLogicFactory;

import io.fabric8.kubernetes.api.model.ConfigMap;
Expand Down Expand Up @@ -173,6 +174,9 @@ public UpdateControl<Keycloak> reconcile(Keycloak kc, Context<Keycloak> context)
var updateLogicControl = updateLogic.decideUpdate();
if (updateLogicControl.isPresent()) {
Log.debug("--- Reconciliation interrupted due to update logic");
if (updateLogic.updateStatusOnInterrupt()) {
return withInterruptedStatus(kc, existingDeployment, updateLogic, updateLogicControl.get(), context);
}
return updateLogicControl.get();
}

Expand Down Expand Up @@ -207,6 +211,29 @@ public UpdateControl<Keycloak> reconcile(Keycloak kc, Context<Keycloak> context)
return updateControl;
}

/**
* Updates the status while the update logic holds back the StatefulSet update. The observedGeneration is not
* advanced, as the current generation is not applied yet.
*/
private UpdateControl<Keycloak> withInterruptedStatus(Keycloak kc, StatefulSet existingDeployment, UpdateLogic updateLogic,
UpdateControl<Keycloak> updateLogicControl, Context<Keycloak> context) {
var currentStatus = kc.getStatus();
// without a previous status, no generation is known to be applied
var observedGeneration = Optional.ofNullable(currentStatus).map(KeycloakStatus::getObservedGeneration)
.orElse(0L);
var statusAggregator = new KeycloakStatusAggregator(currentStatus, observedGeneration);
updateStatus(kc, existingDeployment, statusAggregator, context);
updateLogic.updateStatus(statusAggregator);
var status = statusAggregator.build();
if (status.equals(currentStatus)) {
return updateLogicControl;
}
kc.setStatus(status);
var updateControl = UpdateControl.patchStatus(kc);
updateLogicControl.getScheduleDelay().ifPresent(updateControl::rescheduleAfter);
return updateControl;
}

@Override
public ErrorStatusUpdateControl<Keycloak> updateErrorStatus(Keycloak kc, Context<Keycloak> context, Exception e) {
Log.debug("--- Error reconciling", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ public class KeycloakUpdateJobDependentResource extends CRUDKubernetesDependentR
private static final String LABEL_SELECTOR = "app=keycloak-update-job,app.kubernetes.io/managed-by=keycloak-operator";

// container configuration
private static final String INIT_CONTAINER_NAME = "actual";
private static final String CONTAINER_NAME = "desired";
public static final String INIT_CONTAINER_NAME = "actual";
public static final String CONTAINER_NAME = "desired";
private static final List<String> INIT_CONTAINER_ARGS = List.of("update-compatibility", "metadata", "--file", UPDATES_FILE_PATH);
private static final List<String> CONTAINER_ARGS = List.of("update-compatibility", "check", "--file", UPDATES_FILE_PATH);

// Job and Pod defaults
// Pod is restarted if it fails with an exit code != 0, and we don't want that.
private static final int JOB_RETRIES = 0;
// Job time to live
private static final int JOB_TIME_TO_LIVE_SECONDS = (int) TimeUnit.MINUTES.toSeconds(30);
public static final int JOB_TIME_TO_LIVE_SECONDS = (int) TimeUnit.MINUTES.toSeconds(30);

public KeycloakUpdateJobDependentResource() {
super(Job.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ public interface UpdateLogic {
*/
void updateStatus(KeycloakStatusAggregator statusAggregator);

/**
* The status is usually not updated when {@link #decideUpdate()} interrupts the reconciliation. Return {@code true}
* if the update logic has something to report in the status anyway, e.g. that the decision is retried.
*
* @return {@code true} if the status must be updated although the reconciliation is interrupted.
*/
default boolean updateStatusOnInterrupt() {
return false;
}

}
Loading