fix: moves jgroups.dns.query to a system property (#24057)

* fix: moves jgroups.dns.query to a system property

closes #21830

* removing the dns query from import

* removing the dns query from import

also removing cache-stack
This commit is contained in:
Steven Hawkins 2023-10-20 03:50:29 -04:00 committed by GitHub
parent b05b575646
commit 5ff5e12782
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 11 deletions

View file

@ -65,6 +65,8 @@ import static org.keycloak.operator.crds.v2alpha1.CRDUtils.isTlsConfigured;
@KubernetesDependent(labelSelector = Constants.DEFAULT_LABELS_AS_STRING) @KubernetesDependent(labelSelector = Constants.DEFAULT_LABELS_AS_STRING)
public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependentResource<StatefulSet, Keycloak> { public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependentResource<StatefulSet, Keycloak> {
static final String JGROUPS_DNS_QUERY_PARAM = "-Djgroups.dns.query=";
public static final String OPTIMIZED_ARG = "--optimized"; public static final String OPTIMIZED_ARG = "--optimized";
@Inject @Inject
@ -209,6 +211,7 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent
if (customImage.isPresent()) { if (customImage.isPresent()) {
containerBuilder.addToArgs(OPTIMIZED_ARG); containerBuilder.addToArgs(OPTIMIZED_ARG);
} }
containerBuilder.addToArgs(0, getJGroupsParameter(keycloakCR));
// probes // probes
var tlsConfigured = isTlsConfigured(keycloakCR); var tlsConfigured = isTlsConfigured(keycloakCR);
@ -271,6 +274,10 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent
return baseDeployment; 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) { private void addEnvVarsAndWatchSecrets(StatefulSet baseDeployment, Keycloak keycloakCR) {
var firstClasssEnvVars = distConfigurator.configureDistOptions(keycloakCR); var firstClasssEnvVars = distConfigurator.configureDistOptions(keycloakCR);
@ -351,12 +358,6 @@ public class KeycloakDeploymentDependentResource extends CRUDKubernetesDependent
.endValueFrom() .endValueFrom()
.build()); .build());
envVars.add(
new EnvVarBuilder()
.withName("jgroups.dns.query")
.withValue(getName(keycloakCR) + Constants.KEYCLOAK_DISCOVERY_SERVICE_SUFFIX +"." + keycloakCR.getMetadata().getNamespace())
.build());
return envVars; return envVars;
} }

View file

@ -38,6 +38,7 @@ import org.keycloak.operator.Utils;
import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport; import org.keycloak.operator.crds.v2alpha1.realmimport.KeycloakRealmImport;
import java.util.List; import java.util.List;
import java.util.Set;
import static org.keycloak.operator.controllers.KeycloakDistConfigurator.getKeycloakOptionEnvVarName; import static org.keycloak.operator.controllers.KeycloakDistConfigurator.getKeycloakOptionEnvVarName;
@ -76,7 +77,9 @@ public class KeycloakRealmImportJobDependentResource extends KubernetesDependent
var cacheEnvVarName = getKeycloakOptionEnvVarName("cache"); var cacheEnvVarName = getKeycloakOptionEnvVarName("cache");
var healthEnvVarName = getKeycloakOptionEnvVarName("health-enabled"); 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 // The Job should not connect to the cache
envvars.add(new EnvVarBuilder().withName(cacheEnvVarName).withValue("local").build()); envvars.add(new EnvVarBuilder().withName(cacheEnvVarName).withValue("local").build());

View file

@ -319,6 +319,8 @@ public class BaseOperatorTest implements QuarkusTestAfterEachCallback {
logFailed(k8sclient.apps().deployments().withName("keycloak-operator"), Deployment::getStatus); logFailed(k8sclient.apps().deployments().withName("keycloak-operator"), Deployment::getStatus);
} }
logFailed(k8sclient.apps().statefulSets().withName(POSTGRESQL_NAME), StatefulSet::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 { } finally {
cleanup(); cleanup();
} }

View file

@ -489,7 +489,7 @@ public class KeycloakDeploymentTest extends BaseOperatorTest {
.list() .list()
.getItems(); .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 @Test
@ -512,7 +512,7 @@ public class KeycloakDeploymentTest extends BaseOperatorTest {
.list() .list()
.getItems(); .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().size()).isEqualTo(1);
assertThat(pods.get(0).getSpec().getImagePullSecrets().get(0).getName()).isEqualTo(imagePullSecretName); assertThat(pods.get(0).getSpec().getImagePullSecrets().get(0).getName()).isEqualTo(imagePullSecretName);
} }

View file

@ -194,8 +194,8 @@ public class PodTemplateTest {
// Assert // Assert
assertEquals(1, podTemplate.getSpec().getContainers().get(0).getCommand().size()); assertEquals(1, podTemplate.getSpec().getContainers().get(0).getCommand().size());
assertEquals(command, podTemplate.getSpec().getContainers().get(0).getCommand().get(0)); assertEquals(command, podTemplate.getSpec().getContainers().get(0).getCommand().get(0));
assertEquals(1, podTemplate.getSpec().getContainers().get(0).getArgs().size()); assertEquals(2, podTemplate.getSpec().getContainers().get(0).getArgs().size());
assertEquals(arg, podTemplate.getSpec().getContainers().get(0).getArgs().get(0)); assertEquals(arg, podTemplate.getSpec().getContainers().get(0).getArgs().get(1));
} }
@Test @Test