Skip to content

Commit

Permalink
Fix the Keycloak memory issue on Podman setting JAVA_OPTS_APPEND -XX:…
Browse files Browse the repository at this point in the history
…MaxRAM=1g
  • Loading branch information
jcarranzan committed Oct 30, 2024
1 parent 5e7253b commit 7c151a7
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;

Expand All @@ -22,6 +23,18 @@ protected KeycloakGenericDockerContainerManagedResource(KeycloakContainerManaged
this.model = model;
}

// Currently, we can't properly set the container's memory limit when running with Podman.
// More details on this issue can be found here: https://github.com/quarkus-qe/quarkus-test-suite/issues/2106
private boolean isPodman() {
try {
String dockerVersion = DockerClientFactory.instance().client().versionCmd().exec().getVersion();
return dockerVersion != null && dockerVersion.toLowerCase().contains("podman");
} catch (Exception e) {
Log.warn("Failed to detect container runtime: " + e.getMessage());
return false;
}
}

@Override
protected GenericContainer<?> initContainer() {
GenericContainer<?> container = new GenericContainer<>(model.getImage());
Expand All @@ -40,6 +53,13 @@ protected GenericContainer<?> initContainer() {
}

container.withCreateContainerCmdModifier(cmd -> cmd.withName(DockerUtils.generateDockerContainerName()));

if (isPodman()) {
container.withEnv("JAVA_OPTS_APPEND", String.format("-XX:MaxRAM=%sm", model.getMemoryLimitMiB()));
} else {
container.withCreateContainerCmdModifier(cmd -> Optional.ofNullable(cmd.getHostConfig())
.ifPresent(config -> config.withMemory(convertMiBtoBytes(model.getMemoryLimitMiB()))));
}
container.withCreateContainerCmdModifier(cmd -> Optional.ofNullable(cmd.getHostConfig())
.ifPresent(config -> config.withMemory(convertMiBtoBytes(model.getMemoryLimitMiB()))));

Expand Down

0 comments on commit 7c151a7

Please sign in to comment.