Skip to content

Commit

Permalink
task: use informer rather than 0 interval polling (keycloak#28901)
Browse files Browse the repository at this point in the history
related to: keycloak#28869

Signed-off-by: Steve Hawkins <[email protected]>
  • Loading branch information
shawkins authored Apr 19, 2024
1 parent ef45629 commit d7ef650
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;

import jakarta.inject.Inject;
Expand Down Expand Up @@ -583,24 +586,25 @@ public void testUpgradeRecreatesPods() {
deployKeycloak(k8sclient, kc, true);

var stsGetter = k8sclient.apps().statefulSets().inNamespace(namespace).withName(kc.getMetadata().getName());
final String origImage = stsGetter.get().getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
final String newImage = "quay.io/keycloak/non-existing-keycloak";

kc.getSpec().setImage(newImage);
deployKeycloak(k8sclient, kc, false);

Awaitility.await()
.ignoreExceptions()
.pollInterval(Duration.ZERO) // make the test super fast not to miss the moment when Operator changes the STS
.untilAsserted(() -> {
var sts = stsGetter.get();
assertEquals(1, sts.getStatus().getReplicas());
assertEquals(origImage, sts.getSpec().getTemplate().getSpec().getContainers().get(0).getImage());
var upgradeCondition = k8sclient.resource(kc).informOnCondition(kcs -> {
try {
assertKeycloakStatusCondition(kcs.get(0), KeycloakStatusCondition.READY, false, "Performing Keycloak upgrade");
return true;
} catch (AssertionError e) {
return false;
}
});

var currentKc = k8sclient.resources(Keycloak.class)
.inNamespace(namespace).withName(kc.getMetadata().getName()).get();
assertKeycloakStatusCondition(currentKc, KeycloakStatusCondition.READY, false, "Performing Keycloak upgrade");
});
deployKeycloak(k8sclient, kc, false);
try {
upgradeCondition.get(2, TimeUnit.MINUTES);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new AssertionError(e);
}

Awaitility.await()
.ignoreExceptions()
Expand Down

0 comments on commit d7ef650

Please sign in to comment.