diff --git a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java index 4f85b9d99e..27be028b80 100644 --- a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java +++ b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakDeploymentDependentResource.java @@ -65,6 +65,8 @@ import static org.keycloak.operator.crds.v2alpha1.CRDUtils.isTlsConfigured; @KubernetesDependent(labelSelector = Constants.DEFAULT_LABELS_AS_STRING) public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependentResource { + static final String JGROUPS_DNS_QUERY_PARAM = "-Djgroups.dns.query="; + public static final String OPTIMIZED_ARG = "--optimized"; @Inject @@ -209,6 +211,7 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent if (customImage.isPresent()) { containerBuilder.addToArgs(OPTIMIZED_ARG); } + containerBuilder.addToArgs(0, getJGroupsParameter(keycloakCR)); // probes var tlsConfigured = isTlsConfigured(keycloakCR); @@ -271,6 +274,10 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent return baseDeployment; } + private static String getJGroupsParameter(Keycloak keycloakCR) { + return JGROUPS_DNS_QUERY_PARAM + KeycloakDiscoveryServiceDependentResource.getName(keycloakCR) +"." + keycloakCR.getMetadata().getNamespace(); + } + private void addEnvVarsAndWatchSecrets(StatefulSet baseDeployment, Keycloak keycloakCR) { var firstClasssEnvVars = distConfigurator.configureDistOptions(keycloakCR); @@ -351,12 +358,6 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent .endValueFrom() .build()); - envVars.add( - new EnvVarBuilder() - .withName("jgroups.dns.query") - .withValue(getName(keycloakCR) + Constants.KEYCLOAK_DISCOVERY_SERVICE_SUFFIX +"." + keycloakCR.getMetadata().getNamespace()) - .build()); - return envVars; } diff --git a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportJobDependentResource.java b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportJobDependentResource.java index 2d4310d5b1..6acb9b7bad 100644 --- a/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportJobDependentResource.java +++ b/operator/src/main/java/org/keycloak/operator/controllers/KeycloakRealmImportJobDependentResource.java @@ -38,6 +38,7 @@ import org.keycloak.operator.Utils; import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport; import java.util.List; +import java.util.Set; import static org.keycloak.operator.controllers.KeycloakDistConfigurator.getKeycloakOptionEnvVarName; @@ -76,7 +77,9 @@ public class KeycloakRealmImportJobDependentResource extends KubernetesDependent var cacheEnvVarName = getKeycloakOptionEnvVarName("cache"); var healthEnvVarName = getKeycloakOptionEnvVarName("health-enabled"); - envvars.removeIf(e -> e.getName().equals(cacheEnvVarName) || e.getName().equals(healthEnvVarName)); + var cacheStackEnvVarName = getKeycloakOptionEnvVarName("cache-stack"); + var toRemove = Set.of(cacheEnvVarName, healthEnvVarName, cacheStackEnvVarName); + envvars.removeIf(e -> toRemove.contains(e.getName())); // The Job should not connect to the cache envvars.add(new EnvVarBuilder().withName(cacheEnvVarName).withValue("local").build()); diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java index d08b0b4d41..a3a298080f 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/BaseOperatorTest.java @@ -319,6 +319,8 @@ public class BaseOperatorTest implements QuarkusTestAfterEachCallback { logFailed(k8sclient.apps().deployments().withName("keycloak-operator"), Deployment::getStatus); } logFailed(k8sclient.apps().statefulSets().withName(POSTGRESQL_NAME), StatefulSet::getStatus); + k8sclient.pods().withLabel("app", "keycloak-realm-import").list().getItems().stream() + .forEach(pod -> logFailed(k8sclient.pods().resource(pod), Pod::getStatus)); } finally { cleanup(); } diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java index a327a941e3..23ba52cb33 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/KeycloakDeploymentTest.java @@ -489,7 +489,7 @@ public class KeycloakDeploymentTest extends BaseOperatorTest { .list() .getItems(); - assertThat(pods.get(0).getSpec().getContainers().get(0).getArgs()).containsExactly("--verbose", "start", "--optimized"); + assertThat(pods.get(0).getSpec().getContainers().get(0).getArgs()).endsWith("--verbose", "start", "--optimized"); } @Test @@ -512,7 +512,7 @@ public class KeycloakDeploymentTest extends BaseOperatorTest { .list() .getItems(); - assertThat(pods.get(0).getSpec().getContainers().get(0).getArgs()).containsExactly("--verbose", "start", "--optimized"); + assertThat(pods.get(0).getSpec().getContainers().get(0).getArgs()).endsWith("--verbose", "start", "--optimized"); assertThat(pods.get(0).getSpec().getImagePullSecrets().size()).isEqualTo(1); assertThat(pods.get(0).getSpec().getImagePullSecrets().get(0).getName()).isEqualTo(imagePullSecretName); } diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/unit/PodTemplateTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/unit/PodTemplateTest.java index 3d672e34d5..888b508013 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/unit/PodTemplateTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/unit/PodTemplateTest.java @@ -194,8 +194,8 @@ public class PodTemplateTest { // Assert assertEquals(1, podTemplate.getSpec().getContainers().get(0).getCommand().size()); assertEquals(command, podTemplate.getSpec().getContainers().get(0).getCommand().get(0)); - assertEquals(1, podTemplate.getSpec().getContainers().get(0).getArgs().size()); - assertEquals(arg, podTemplate.getSpec().getContainers().get(0).getArgs().get(0)); + assertEquals(2, podTemplate.getSpec().getContainers().get(0).getArgs().size()); + assertEquals(arg, podTemplate.getSpec().getContainers().get(0).getArgs().get(1)); } @Test