Stops the recreation of managed Keycloak Statefulset Pods when Keycloak Operator restarts occasionally. (#20187)

This commit is contained in:
Andre Nascimento RH 2023-05-09 19:33:12 +02:00 committed by GitHub
parent 025778fe9c
commit 851ecb43fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 13 deletions

View file

@ -16,6 +16,9 @@
*/
package org.keycloak.operator;
import org.keycloak.operator.crds.v2alpha1.deployment.ValueOrSecret;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -39,13 +42,14 @@ public final class Constants {
.map(e -> e.getKey() + "=" + e.getValue())
.collect(Collectors.joining(","));
public static final Map<String, String> DEFAULT_DIST_CONFIG = Map.of(
"health-enabled","true",
"cache", "ispn",
"cache-stack", "kubernetes",
"proxy", "passthrough"
public static final List<ValueOrSecret> DEFAULT_DIST_CONFIG_LIST = List.of(
new ValueOrSecret("health-enabled", "true"),
new ValueOrSecret("cache", "ispn"),
new ValueOrSecret("cache-stack", "kubernetes"),
new ValueOrSecret("proxy", "passthrough")
);
public static final Integer KEYCLOAK_HTTP_PORT = 8080;
public static final Integer KEYCLOAK_HTTPS_PORT = 8443;
public static final String KEYCLOAK_SERVICE_PROTOCOL = "TCP";

View file

@ -429,19 +429,17 @@ public class KeycloakDeployment extends OperatorManagedResource implements Statu
private List<EnvVar> getEnvVars() {
// default config values
List<ValueOrSecret> serverConfig = Constants.DEFAULT_DIST_CONFIG.entrySet().stream()
.map(e -> new ValueOrSecret(e.getKey(), e.getValue()))
.collect(Collectors.toList());
List<ValueOrSecret> serverConfigsList = new ArrayList<>(Constants.DEFAULT_DIST_CONFIG_LIST);
// merge with the CR; the values in CR take precedence
if (keycloakCR.getSpec().getAdditionalOptions() != null) {
serverConfig.removeAll(keycloakCR.getSpec().getAdditionalOptions());
serverConfig.addAll(keycloakCR.getSpec().getAdditionalOptions());
serverConfigsList.removeAll(keycloakCR.getSpec().getAdditionalOptions());
serverConfigsList.addAll(keycloakCR.getSpec().getAdditionalOptions());
}
// set env vars
serverConfigSecretsNames = new HashSet<>();
List<EnvVar> envVars = serverConfig.stream()
List<EnvVar> envVars = serverConfigsList.stream()
.map(v -> {
var envBuilder = new EnvVarBuilder().withName(KeycloakDistConfigurator.getKeycloakOptionEnvVarName(v.getName()));
var secret = v.getSecret();

View file

@ -145,11 +145,19 @@ public class KeycloakDeploymentTest extends BaseOperatorTest {
deployKeycloak(k8sclient, defaultKCDeploy, false);
assertThat(
Constants.DEFAULT_DIST_CONFIG.get(valueSecretHealthProp.getName())
Constants.DEFAULT_DIST_CONFIG_LIST.stream()
.filter(oneValueOrSecret -> oneValueOrSecret.getName().equalsIgnoreCase(valueSecretHealthProp.getName()))
.findFirst()
.get()
.getValue()
).isEqualTo("true"); // just a sanity check default values did not change
assertThat(
Constants.DEFAULT_DIST_CONFIG.get(valueSecretProxyProp.getName())
Constants.DEFAULT_DIST_CONFIG_LIST.stream()
.filter(oneValueOrSecret -> oneValueOrSecret.getName().equalsIgnoreCase(valueSecretProxyProp.getName()))
.findFirst()
.get()
.getValue()
).isEqualTo("passthrough"); // just a sanity check default values did not change
Awaitility.await()