Skip to content

Commit 0f91e67

Browse files
authored
Feature flag: rolling-updates
Closes #36840 Signed-off-by: Pedro Ruivo <[email protected]>
1 parent 690b0e4 commit 0f91e67

File tree

11 files changed

+70
-18
lines changed

11 files changed

+70
-18
lines changed

common/src/main/java/org/keycloak/common/Profile.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public enum Feature {
131131

132132
USER_EVENT_METRICS("Collect metrics based on user events", Type.PREVIEW),
133133

134-
IPA_TUURA_FEDERATION("IPA-Tuura user federation provider", Type.EXPERIMENTAL)
134+
IPA_TUURA_FEDERATION("IPA-Tuura user federation provider", Type.EXPERIMENTAL),
135+
136+
ROLLING_UPDATES("Rolling Updates", Type.PREVIEW),
135137
;
136138

137139
private final Type type;

docs/guides/operator/advanced-configuration.adoc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ Check the https://kubernetes.io/docs/concepts/services-networking/network-polici
443443

444444
The Keycloak Operator offers updates strategies to control how the Operator handles changes to the Keycloak CR.
445445

446+
[CAUTION]
447+
====
448+
While on preview stage, the feature `rolling-updates` must be enabled.
449+
Otherwise, the {project_name} Operator will fail.
450+
====
451+
446452
**Supported Updates Types:**
447453

448454
Rolling Updates:: Update the StatefulSet in a rolling fashion, minimizing downtime (requires multiple replicas).
@@ -466,11 +472,14 @@ kind: Keycloak
466472
metadata:
467473
name: example-kc
468474
spec:
475+
features:
476+
enabled:
477+
- rolling-updates # <1>
469478
update:
470-
strategy: Recreate|<not set> # <1>
479+
strategy: Recreate|<not set> # <2>
471480
----
472-
473-
<1> Set the desired update strategy here (Recreate in this example).
481+
<1> Enable preview feature `rolling-updates`.
482+
<2> Set the desired update strategy here (Recreate in this example).
474483

475484
[%autowidth]
476485
.Possible field values

docs/guides/server/update-compatibility.adoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ preview="true"
99
previewDiscussionLink="https://github.com/keycloak/keycloak/discussions/36785"
1010
>
1111

12-
// TODO Link to discussion?
12+
[CAUTION]
13+
====
14+
While on preview stage, the feature `rolling-updates` must be enabled.
15+
Otherwise, the commands will fail.
16+
====
1317

1418
The goal of this tool is to assist with modifying a {project_name} deployment, whether upgrading to a new version, enabling/disabling features, or changing configuration.
1519
The outcome will indicate whether a rolling upgrade is possible or if a recreate upgrade is required.
@@ -124,6 +128,10 @@ m|2
124128
m|3
125129
|Rolling Upgrade is not possible.
126130
The deployment must be shut down before applying the new configuration.
131+
132+
m|4
133+
|Rolling Upgrade is not possible.
134+
The feature `rolling-updates` is disabled.
127135
|===
128136

129137
</@tmpl.guide>

docs/guides/templates/kc.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ bin/kc.[sh|bat] bootstrap-admin ${parameters}
5050
<#macro updatecompatibility parameters>
5151
[source,bash]
5252
----
53-
bin/kc.[sh|bat] update-compatibility ${parameters}
53+
bin/kc.[sh|bat] update-compatibility ${parameters} --features=rolling-updates
5454
----
5555
</#macro>

operator/scripts/Dockerfile-custom-image

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ ARG IMAGE=keycloak
22
ARG VERSION=latest
33
FROM $IMAGE:$VERSION
44

5-
RUN /opt/keycloak/bin/kc.sh build --db=postgres --health-enabled=true
5+
RUN /opt/keycloak/bin/kc.sh build --db=postgres --health-enabled=true --features=rolling-updates

operator/src/test/java/org/keycloak/operator/testsuite/integration/UpgradeTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.keycloak.operator.testsuite.integration;
1919

20+
import java.util.List;
2021
import java.util.concurrent.CompletableFuture;
2122
import java.util.concurrent.ExecutionException;
2223
import java.util.concurrent.TimeUnit;
@@ -27,10 +28,11 @@
2728
import org.awaitility.Awaitility;
2829
import org.junit.jupiter.params.ParameterizedTest;
2930
import org.junit.jupiter.params.provider.MethodSource;
31+
import org.keycloak.common.Profile;
3032
import org.keycloak.operator.crds.v2alpha1.deployment.Keycloak;
3133
import org.keycloak.operator.crds.v2alpha1.deployment.KeycloakStatusCondition;
3234
import org.keycloak.operator.crds.v2alpha1.deployment.ValueOrSecret;
33-
import org.keycloak.operator.crds.v2alpha1.deployment.spec.UnsupportedSpec;
35+
import org.keycloak.operator.crds.v2alpha1.deployment.spec.FeatureSpec;
3436
import org.keycloak.operator.crds.v2alpha1.deployment.spec.UpdateSpec;
3537
import org.keycloak.operator.upgrade.UpdateStrategy;
3638

@@ -105,11 +107,12 @@ private static Keycloak createInitialDeployment(UpdateStrategy updateStrategy) {
105107
}
106108
var updateSpec = new UpdateSpec();
107109
updateSpec.setStrategy(updateStrategy);
110+
kc.getSpec().setUpdateSpec(updateSpec);
108111

109-
if (kc.getSpec().getUnsupported() == null) {
110-
kc.getSpec().setUnsupported(new UnsupportedSpec());
112+
if (kc.getSpec().getFeatureSpec() == null) {
113+
kc.getSpec().setFeatureSpec(new FeatureSpec());
111114
}
112-
kc.getSpec().setUpdateSpec(updateSpec);
115+
kc.getSpec().getFeatureSpec().setEnabledFeatures(List.of(Profile.Feature.ROLLING_UPDATES.getKey()));
113116
return kc;
114117
}
115118

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractUpdatesCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,8 @@ void printPreviewWarning() {
8080
printError("Warning! This command is preview and is not recommended for use in production. It may change or be removed at a future release.");
8181
}
8282

83+
void printFeatureDisabled() {
84+
printError("Unable to use this command. The preview feature 'rolling-updates' is not enabled.");
85+
}
86+
8387
}

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/UpdateCompatibilityCheck.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.io.File;
2121
import java.io.IOException;
2222

23+
import org.keycloak.common.Profile;
2324
import org.keycloak.quarkus.runtime.cli.PropertyException;
25+
import org.keycloak.quarkus.runtime.compatibility.CompatibilityResult;
2426
import org.keycloak.quarkus.runtime.compatibility.ServerInfo;
2527
import org.keycloak.util.JsonSerialization;
2628
import picocli.CommandLine;
@@ -41,6 +43,11 @@ public class UpdateCompatibilityCheck extends AbstractUpdatesCommand {
4143

4244
@Override
4345
public void run() {
46+
if (!Profile.isFeatureEnabled(Profile.Feature.ROLLING_UPDATES)) {
47+
printFeatureDisabled();
48+
picocli.exit(CompatibilityResult.FEATURE_DISABLED);
49+
return;
50+
}
4451
printPreviewWarning();
4552
validateConfig();
4653
var info = readServerInfo();

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/UpdateCompatibilityMetadata.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import java.io.IOException;
2222

2323
import com.fasterxml.jackson.core.JsonProcessingException;
24+
import org.keycloak.common.Profile;
2425
import org.keycloak.quarkus.runtime.cli.PropertyException;
26+
import org.keycloak.quarkus.runtime.compatibility.CompatibilityResult;
2527
import org.keycloak.quarkus.runtime.compatibility.ServerInfo;
2628
import org.keycloak.util.JsonSerialization;
2729
import picocli.CommandLine;
@@ -41,6 +43,11 @@ public class UpdateCompatibilityMetadata extends AbstractUpdatesCommand {
4143

4244
@Override
4345
public void run() {
46+
if (!Profile.isFeatureEnabled(Profile.Feature.ROLLING_UPDATES)) {
47+
printFeatureDisabled();
48+
picocli.exit(CompatibilityResult.FEATURE_DISABLED);
49+
return;
50+
}
4451
printPreviewWarning();
4552
validateConfig();
4653
var info = compatibilityManager.current();

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/compatibility/CompatibilityResult.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
public interface CompatibilityResult {
2929

3030
int ROLLING_UPGRADE_EXIT_CODE = 0;
31-
int RECREATE_UPGRADE_EXIT_CODE = 4;
31+
// see picocli.CommandLine.ExitCode
32+
// 1 -> software error
33+
// 2 -> usage error
34+
int RECREATE_UPGRADE_EXIT_CODE = 3;
35+
int FEATURE_DISABLED = 4;
3236

3337
/**
3438
* The compatible {@link CompatibilityResult} implementation

0 commit comments

Comments
 (0)