fix: adjusting the test to use a fully valid config
closes: #28638 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
004f419fd0
commit
a3b4b487d5
2 changed files with 130 additions and 26 deletions
|
@ -20,9 +20,11 @@ package org.keycloak.operator.testsuite.integration;
|
||||||
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
|
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
|
||||||
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
|
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
|
||||||
import io.fabric8.kubernetes.client.dsl.Resource;
|
import io.fabric8.kubernetes.client.dsl.Resource;
|
||||||
|
import io.fabric8.kubernetes.client.utils.Serialization;
|
||||||
import io.quarkus.logging.Log;
|
import io.quarkus.logging.Log;
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -32,6 +34,8 @@ import org.keycloak.operator.crds.v2alpha1.deployment.spec.CacheSpecBuilder;
|
||||||
import org.keycloak.operator.testsuite.utils.CRAssert;
|
import org.keycloak.operator.testsuite.utils.CRAssert;
|
||||||
import org.keycloak.operator.testsuite.utils.K8sUtils;
|
import org.keycloak.operator.testsuite.utils.K8sUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -49,7 +53,7 @@ public class CacheTest extends BaseOperatorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateCacheConfigMapFileAfterDeployment() {
|
public void testCreateCacheConfigMapFileAfterDeployment() {
|
||||||
var kc = getTestKeycloakDeployment(true);
|
var kc = getTestKeycloakDeployment(false);
|
||||||
var deploymentName = kc.getMetadata().getName();
|
var deploymentName = kc.getMetadata().getName();
|
||||||
kc.getSpec().setCacheSpec(new CacheSpecBuilder().withNewConfigMapFile("file", CONFIGMAP_NAME, false).build());
|
kc.getSpec().setCacheSpec(new CacheSpecBuilder().withNewConfigMapFile("file", CONFIGMAP_NAME, false).build());
|
||||||
|
|
||||||
|
@ -61,14 +65,34 @@ public class CacheTest extends BaseOperatorTest {
|
||||||
Resource<StatefulSet> stsResource = k8sclient.resources(StatefulSet.class).withName(deploymentName);
|
Resource<StatefulSet> stsResource = k8sclient.resources(StatefulSet.class).withName(deploymentName);
|
||||||
Resource<Keycloak> keycloakResource = k8sclient.resources(Keycloak.class).withName(deploymentName);
|
Resource<Keycloak> keycloakResource = k8sclient.resources(Keycloak.class).withName(deploymentName);
|
||||||
// expect no errors and not ready, which means we'll keep reconciling
|
// expect no errors and not ready, which means we'll keep reconciling
|
||||||
Awaitility.await().ignoreExceptions().atMost(2, TimeUnit.MINUTES).untilAsserted(() -> {
|
Awaitility.await().ignoreExceptions().atMost(2, TimeUnit.MINUTES).during(10, TimeUnit.SECONDS)
|
||||||
assertThat(stsResource.get()).isNotNull();
|
.untilAsserted(() -> {
|
||||||
Keycloak keycloak = keycloakResource.get();
|
StatefulSet deployment = stsResource.get();
|
||||||
CRAssert.assertKeycloakStatusCondition(keycloak, KeycloakStatusCondition.HAS_ERRORS, false);
|
assertThat(deployment).isNotNull();
|
||||||
CRAssert.assertKeycloakStatusCondition(keycloak, KeycloakStatusCondition.READY, false);
|
Keycloak keycloak = keycloakResource.get();
|
||||||
|
CRAssert.assertKeycloakStatusCondition(keycloak, KeycloakStatusCondition.HAS_ERRORS, false);
|
||||||
|
CRAssert.assertKeycloakStatusCondition(keycloak, KeycloakStatusCondition.READY, false);
|
||||||
|
var pod = k8sclient.pods().withLabelSelector(deployment.getSpec().getSelector()).list().getItems()
|
||||||
|
.get(0);
|
||||||
|
assertThat(pod.getStatus().getPhase()).isEqualTo("Pending");
|
||||||
|
});
|
||||||
|
|
||||||
|
// should allow the deployment to proceed, but it won't become ready
|
||||||
|
Log.info("Checking Operator has picked up a bad configmap");
|
||||||
|
createCacheConfigMap(false);
|
||||||
|
|
||||||
|
Awaitility.await().ignoreExceptions().atMost(3, TimeUnit.MINUTES).untilAsserted(() -> {
|
||||||
|
StatefulSet deployment = stsResource.get();
|
||||||
|
assertThat(deployment).isNotNull();
|
||||||
|
// check the pod directly - it takes longer for us to update our Keycloak status
|
||||||
|
// with an error
|
||||||
|
var pod = k8sclient.pods().withLabelSelector(deployment.getSpec().getSelector()).list().getItems().get(0);
|
||||||
|
assertThat(Serialization.asYaml(pod.getStatus().getContainerStatuses().get(0))).contains("terminated");
|
||||||
});
|
});
|
||||||
|
|
||||||
createCacheConfigMap();
|
// should become fully ready
|
||||||
|
Log.info("Checking Operator has picked up a valid configmap");
|
||||||
|
createCacheConfigMap(true);
|
||||||
|
|
||||||
K8sUtils.waitForKeycloakToBeReady(k8sclient, kc);
|
K8sUtils.waitForKeycloakToBeReady(k8sclient, kc);
|
||||||
}
|
}
|
||||||
|
@ -78,28 +102,23 @@ public class CacheTest extends BaseOperatorTest {
|
||||||
var kc = getTestKeycloakDeployment(true);
|
var kc = getTestKeycloakDeployment(true);
|
||||||
kc.getSpec().setCacheSpec(new CacheSpecBuilder().withNewConfigMapFile("file", CONFIGMAP_NAME, false).build());
|
kc.getSpec().setCacheSpec(new CacheSpecBuilder().withNewConfigMapFile("file", CONFIGMAP_NAME, false).build());
|
||||||
|
|
||||||
createCacheConfigMap();
|
createCacheConfigMap(true);
|
||||||
|
|
||||||
|
// should immediately seem ready because probes are disabled
|
||||||
deployKeycloak(k8sclient, kc, true);
|
deployKeycloak(k8sclient, kc, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createCacheConfigMap() {
|
private void createCacheConfigMap(boolean valid) {
|
||||||
k8sclient.configMaps()
|
try {
|
||||||
.resource(new ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata()
|
K8sUtils.set(k8sclient,
|
||||||
.addToData("file",
|
new ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata()
|
||||||
"""
|
.addToData("file",
|
||||||
<infinispan
|
valid ? IOUtils.resourceToString("/cache-ispn.xml", StandardCharsets.UTF_8)
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
: "this isn't right")
|
||||||
xsi:schemaLocation="urn:infinispan:config:14.0 http://www.infinispan.org/schemas/infinispan-config-14.0.xsd"
|
.build());
|
||||||
xmlns="urn:infinispan:config:14.0">
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
<cache-container name="keycloak">
|
}
|
||||||
<local-cache name="default">
|
|
||||||
<transaction transaction-manager-lookup="org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup"/>
|
|
||||||
</local-cache>
|
|
||||||
</cache-contianer>
|
|
||||||
</infinispan>""")
|
|
||||||
.build())
|
|
||||||
.create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
85
operator/src/test/resources/cache-ispn.xml
Normal file
85
operator/src/test/resources/cache-ispn.xml
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright 2019 Red Hat, Inc. and/or its affiliates
|
||||||
|
~ and other contributors as indicated by the @author tags.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<infinispan
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="urn:infinispan:config:14.0 http://www.infinispan.org/schemas/infinispan-config-14.0.xsd"
|
||||||
|
xmlns="urn:infinispan:config:14.0">
|
||||||
|
|
||||||
|
<cache-container name="keycloak">
|
||||||
|
<transport lock-timeout="60000"/>
|
||||||
|
<local-cache name="realms" simple-cache="true">
|
||||||
|
<encoding>
|
||||||
|
<key media-type="application/x-java-object"/>
|
||||||
|
<value media-type="application/x-java-object"/>
|
||||||
|
</encoding>
|
||||||
|
<memory max-count="10000"/>
|
||||||
|
</local-cache>
|
||||||
|
<local-cache name="users" simple-cache="true">
|
||||||
|
<encoding>
|
||||||
|
<key media-type="application/x-java-object"/>
|
||||||
|
<value media-type="application/x-java-object"/>
|
||||||
|
</encoding>
|
||||||
|
<memory max-count="10000"/>
|
||||||
|
</local-cache>
|
||||||
|
<distributed-cache name="sessions" owners="2">
|
||||||
|
<expiration lifespan="-1"/>
|
||||||
|
</distributed-cache>
|
||||||
|
<distributed-cache name="authenticationSessions" owners="2">
|
||||||
|
<expiration lifespan="-1"/>
|
||||||
|
</distributed-cache>
|
||||||
|
<distributed-cache name="offlineSessions" owners="2">
|
||||||
|
<expiration lifespan="-1"/>
|
||||||
|
</distributed-cache>
|
||||||
|
<distributed-cache name="clientSessions" owners="2">
|
||||||
|
<expiration lifespan="-1"/>
|
||||||
|
</distributed-cache>
|
||||||
|
<distributed-cache name="offlineClientSessions" owners="2">
|
||||||
|
<expiration lifespan="-1"/>
|
||||||
|
</distributed-cache>
|
||||||
|
<distributed-cache name="loginFailures" owners="2">
|
||||||
|
<expiration lifespan="-1"/>
|
||||||
|
</distributed-cache>
|
||||||
|
<local-cache name="authorization" simple-cache="true">
|
||||||
|
<encoding>
|
||||||
|
<key media-type="application/x-java-object"/>
|
||||||
|
<value media-type="application/x-java-object"/>
|
||||||
|
</encoding>
|
||||||
|
<memory max-count="10000"/>
|
||||||
|
</local-cache>
|
||||||
|
<replicated-cache name="work">
|
||||||
|
<expiration lifespan="-1"/>
|
||||||
|
</replicated-cache>
|
||||||
|
<local-cache name="keys" simple-cache="true">
|
||||||
|
<encoding>
|
||||||
|
<key media-type="application/x-java-object"/>
|
||||||
|
<value media-type="application/x-java-object"/>
|
||||||
|
</encoding>
|
||||||
|
<expiration max-idle="3600000"/>
|
||||||
|
<memory max-count="1000"/>
|
||||||
|
</local-cache>
|
||||||
|
<distributed-cache name="actionTokens" owners="2">
|
||||||
|
<encoding>
|
||||||
|
<key media-type="application/x-java-object"/>
|
||||||
|
<value media-type="application/x-java-object"/>
|
||||||
|
</encoding>
|
||||||
|
<expiration max-idle="-1" lifespan="-1" interval="300000"/>
|
||||||
|
<memory max-count="-1"/>
|
||||||
|
</distributed-cache>
|
||||||
|
</cache-container>
|
||||||
|
</infinispan>
|
Loading…
Reference in a new issue