Switch to auto-build off in case of custom images

This commit is contained in:
andreaTP 2022-03-21 17:52:00 +00:00 committed by Bruno Oliveira da Silva
parent 298ce1888b
commit f93a7d63f7
8 changed files with 73 additions and 4 deletions

View file

@ -58,6 +58,12 @@ jobs:
eval $(minikube -p minikube docker-env)
docker build --build-arg KEYCLOAK_DIST=$(ls keycloak-*.tar.gz) . -t keycloak:${GITHUB_SHA}
- name: Build a custom pre-augmented Keycloak Docker image
working-directory: operator
run: |
eval $(minikube -p minikube docker-env)
./scripts/build-testing-docker-images.sh ${GITHUB_SHA} keycloak
- name: Test operator running locally
working-directory: operator
run: |
@ -65,7 +71,8 @@ jobs:
-Dquarkus.kubernetes.deployment-target=kubernetes \
-Doperator.keycloak.image=keycloak:${GITHUB_SHA} \
-Doperator.keycloak.image-pull-policy=Never \
-Dtest.operator.kubernetes.ip=$(minikube ip)
-Dtest.operator.kubernetes.ip=$(minikube ip) \
-Dtest.operator.custom.image=custom-keycloak:${GITHUB_SHA}
- name: Test operator running in cluster
working-directory: operator
@ -76,4 +83,5 @@ jobs:
-Dquarkus.kubernetes.deployment-target=kubernetes \
-Dquarkus.jib.jvm-arguments="-Djava.util.logging.manager=org.jboss.logmanager.LogManager","-Doperator.keycloak.image=keycloak:${GITHUB_SHA}","-Doperator.keycloak.image-pull-policy=Never" \
--no-transfer-progress -Dtest.operator.deployment=remote \
-Dtest.operator.kubernetes.ip=$(minikube ip)
-Dtest.operator.kubernetes.ip=$(minikube ip) \
-Dtest.operator.custom.image=custom-keycloak:${GITHUB_SHA}

View file

@ -90,3 +90,15 @@ On Linux or on Mac using `minikube` on a VM, instead you should pass this additi
```bash
-Dtest.operator.kubernetes.ip=$(minikube ip)
```
To avoid skipping tests that are depending on custom Keycloak images, you need to build those first:
```bash
./build-testing-docker-images.sh <optional/keycloak-version> <optional/keycloak-image-name>
```
And run the tests passing an extra Java property:
```bash
-Dtest.operator.custom.image=custom-keycloak:latest
```

View file

@ -0,0 +1,5 @@
ARG IMAGE=keycloak
ARG VERSION=latest
FROM $IMAGE:$VERSION
RUN /opt/keycloak/bin/kc.sh build --db=postgres --health-enabled=true

View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
VERSION="${1:-latest}"
KEYCLOAK_IMAGE="${2:-quay.io/keycloak/keycloak}"
echo "Using version: $VERSION"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
docker build -f ${SCRIPT_DIR}/Dockerfile-custom-image \
--build-arg IMAGE=${KEYCLOAK_IMAGE} \
--build-arg VERSION=${VERSION} \
-t custom-keycloak:${VERSION} ${SCRIPT_DIR}

View file

@ -402,7 +402,12 @@ public class KeycloakDeployment extends OperatorManagedResource implements Statu
baseDeployment.getSpec().getTemplate().getMetadata().setLabels(Constants.DEFAULT_LABELS);
Container container = baseDeployment.getSpec().getTemplate().getSpec().getContainers().get(0);
container.setImage(Optional.ofNullable(keycloakCR.getSpec().getImage()).orElse(config.keycloak().image()));
var customImage = Optional.ofNullable(keycloakCR.getSpec().getImage());
container.setImage(customImage.orElse(config.keycloak().image()));
if (customImage.isEmpty()) {
container.getArgs().add("--auto-build");
}
container.setImagePullPolicy(config.keycloak().imagePullPolicy());
container.setEnv(getEnvVars());

View file

@ -19,7 +19,6 @@ spec:
containers:
- args:
- start
- --auto-build
imagePullPolicy: Always
name: keycloak
ports:

View file

@ -42,6 +42,7 @@ public abstract class ClusterOperatorTest {
public static final String OPERATOR_DEPLOYMENT_PROP = "test.operator.deployment";
public static final String TARGET_KUBERNETES_GENERATED_YML_FOLDER = "target/kubernetes/";
public static final String OPERATOR_KUBERNETES_IP = "test.operator.kubernetes.ip";
public static final String OPERATOR_CUSTOM_IMAGE = "test.operator.custom.image";
public static final String TEST_RESULTS_DIR = "target/operator-test-results/";
public static final String POD_LOGS_DIR = TEST_RESULTS_DIR + "pod-logs/";
@ -55,6 +56,7 @@ public abstract class ClusterOperatorTest {
protected static String namespace;
protected static String deploymentTarget;
protected static String kubernetesIp;
protected static String customImage;
private static Operator operator;
@ -65,6 +67,7 @@ public abstract class ClusterOperatorTest {
operatorDeployment = ConfigProvider.getConfig().getOptionalValue(OPERATOR_DEPLOYMENT_PROP, OperatorDeployment.class).orElse(OperatorDeployment.local);
deploymentTarget = ConfigProvider.getConfig().getOptionalValue(QUARKUS_KUBERNETES_DEPLOYMENT_TARGET, String.class).orElse("kubernetes");
kubernetesIp = ConfigProvider.getConfig().getOptionalValue(OPERATOR_KUBERNETES_IP, String.class).orElse("localhost");
customImage = ConfigProvider.getConfig().getOptionalValue(OPERATOR_CUSTOM_IMAGE, String.class).orElse(null);
setDefaultAwaitilityTimings();
calculateNamespace();

View file

@ -6,6 +6,7 @@ import io.quarkus.logging.Log;
import io.quarkus.test.junit.QuarkusTest;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.keycloak.operator.utils.K8sUtils;
import org.keycloak.operator.v2alpha1.KeycloakAdminSecret;
import org.keycloak.operator.v2alpha1.KeycloakDeployment;
@ -325,4 +326,27 @@ public class KeycloakDeploymentE2EIT extends ClusterOperatorTest {
}
}
@Test
@EnabledIfSystemProperty(named = OPERATOR_CUSTOM_IMAGE, matches = ".+")
public void testCustomImage() {
try {
var kc = getDefaultKeycloakDeployment();
kc.getSpec().setImage(customImage);
deployKeycloak(k8sclient, kc, true);
var pods = k8sclient
.pods()
.inNamespace(namespace)
.withLabels(Constants.DEFAULT_LABELS)
.list()
.getItems();
assertEquals(1, pods.get(0).getSpec().getContainers().get(0).getArgs().size());
assertEquals("start", pods.get(0).getSpec().getContainers().get(0).getArgs().get(0));
} catch (Exception e) {
savePodLogs();
throw e;
}
}
}