Fix running operator image tests with prebuilt image

Closes #9898

Co-authored-by: Andrea Peruffo <andrea.peruffo1982@gmail.com>
This commit is contained in:
Dominik Guhr 2022-04-28 13:21:55 +02:00 committed by Bruno Oliveira da Silva
parent 5e5cfff4e2
commit c4001ba198
4 changed files with 25 additions and 18 deletions

View file

@ -81,7 +81,7 @@ jobs:
- name: Test operator running locally - name: Test operator running locally
run: | run: |
mvn clean verify -Poperator -pl :keycloak-operator -am \ mvn clean verify -Poperator -pl :keycloak-operator -am \
-Dquarkus.kubernetes.deployment-target=kubernetes \ -Dquarkus.kubernetes.image-pull-policy=IfNotPresent \
-Doperator.keycloak.image=keycloak:${{ steps.vars.outputs.version }} \ -Doperator.keycloak.image=keycloak:${{ steps.vars.outputs.version }} \
-Dtest.operator.custom.image=custom-keycloak:${{ steps.vars.outputs.version }} \ -Dtest.operator.custom.image=custom-keycloak:${{ steps.vars.outputs.version }} \
-Doperator.keycloak.image-pull-policy=Never \ -Doperator.keycloak.image-pull-policy=Never \
@ -128,7 +128,7 @@ jobs:
eval $(minikube -p minikube docker-env) eval $(minikube -p minikube docker-env)
mvn clean verify -Poperator -pl :keycloak-operator -am \ mvn clean verify -Poperator -pl :keycloak-operator -am \
-Dquarkus.container-image.build=true \ -Dquarkus.container-image.build=true \
-Dquarkus.kubernetes.deployment-target=kubernetes \ -Dquarkus.kubernetes.image-pull-policy=IfNotPresent \
-Doperator.keycloak.image=keycloak:${{ steps.vars.outputs.version }} \ -Doperator.keycloak.image=keycloak:${{ steps.vars.outputs.version }} \
-Dquarkus.jib.jvm-arguments="-Djava.util.logging.manager=org.jboss.logmanager.LogManager","-Doperator.keycloak.image-pull-policy=Never" \ -Dquarkus.jib.jvm-arguments="-Djava.util.logging.manager=org.jboss.logmanager.LogManager","-Doperator.keycloak.image-pull-policy=Never" \
-Dtest.operator.custom.image=custom-keycloak:${{ steps.vars.outputs.version }} \ -Dtest.operator.custom.image=custom-keycloak:${{ steps.vars.outputs.version }} \

View file

@ -77,7 +77,7 @@ Testing allows 2 methods specified in the property `test.operator.deployment` :
mvn clean verify \ mvn clean verify \
-Dquarkus.container-image.build=true \ -Dquarkus.container-image.build=true \
-Dquarkus.container-image.tag=test \ -Dquarkus.container-image.tag=test \
-Dquarkus.kubernetes.deployment-target=kubernetes \ -Dquarkus.kubernetes.image-pull-policy=IfNotPresent \
-Dtest.operator.deployment=remote -Dtest.operator.deployment=remote
``` ```
@ -102,3 +102,18 @@ And run the tests passing an extra Java property:
```bash ```bash
-Dtest.operator.custom.image=custom-keycloak:latest -Dtest.operator.custom.image=custom-keycloak:latest
``` ```
### Testing using a pre-built operator image from a remote registry
You can run the testsuite using an already built operator image from a remote image registry.
To do this, you need to set `quarkus.container-image.build=false` and specify the desired image
you want to use by setting `quarkus.container-image.image=<your-image>:<your-tag>`
#### Example:
```bash
mvn clean verify \
-Dquarkus.container-image.build=false \
-Dquarkus.container-image.image=quay.io/keycloak/keycloak-operator:nightly \
-Dtest.operator.deployment=remote
```

View file

@ -0,0 +1 @@
kubernetes.yml

View file

@ -96,19 +96,9 @@ public abstract class ClusterOperatorTest {
} }
private static void createRBACresourcesAndOperatorDeployment() throws FileNotFoundException { private static void createRBACresourcesAndOperatorDeployment() throws FileNotFoundException {
Log.info("Creating RBAC into Namespace " + namespace); Log.info("Creating RBAC and Deployment into Namespace " + namespace);
List<HasMetadata> hasMetadata = k8sclient.load(new FileInputStream(TARGET_KUBERNETES_GENERATED_YML_FOLDER + deploymentTarget + ".yml")) k8sclient.load(new FileInputStream(TARGET_KUBERNETES_GENERATED_YML_FOLDER + deploymentTarget + ".yml"))
.inNamespace(namespace).get(); .inNamespace(namespace).createOrReplace();
hasMetadata.stream()
.map(b -> {
if ("Deployment".equalsIgnoreCase(b.getKind()) && b.getMetadata().getName().contains("operator")) {
((Deployment) b).getSpec().getTemplate().getSpec().getContainers().get(0).setImagePullPolicy("Never");
}
return b;
}).forEach(c -> {
Log.info("processing part : " + c.getKind() + "--" + c.getMetadata().getName() + " -- " + namespace);
k8sclient.resource(c).inNamespace(namespace).createOrReplace();
});
} }
private static void cleanRBACresourcesAndOperatorDeployment() throws FileNotFoundException { private static void cleanRBACresourcesAndOperatorDeployment() throws FileNotFoundException {
@ -116,6 +106,7 @@ public abstract class ClusterOperatorTest {
k8sclient.load(new FileInputStream(TARGET_KUBERNETES_GENERATED_YML_FOLDER +deploymentTarget+".yml")) k8sclient.load(new FileInputStream(TARGET_KUBERNETES_GENERATED_YML_FOLDER +deploymentTarget+".yml"))
.inNamespace(namespace).delete(); .inNamespace(namespace).delete();
} }
private static void createCRDs() { private static void createCRDs() {
Log.info("Creating CRDs"); Log.info("Creating CRDs");
try { try {
@ -134,7 +125,7 @@ public abstract class ClusterOperatorTest {
private static void registerReconcilers() { private static void registerReconcilers() {
Log.info("Registering reconcilers for operator : " + operator + " [" + operatorDeployment + "]"); Log.info("Registering reconcilers for operator : " + operator + " [" + operatorDeployment + "]");
for (Reconciler reconciler : reconcilers) { for (Reconciler<?> reconciler : reconcilers) {
final var config = configuration.getConfigurationFor(reconciler); final var config = configuration.getConfigurationFor(reconciler);
if (!config.isRegistrationDelayed()) { if (!config.isRegistrationDelayed()) {
Log.info("Register and apply : " + reconciler.getClass().getName()); Log.info("Register and apply : " + reconciler.getClass().getName());
@ -216,7 +207,7 @@ public abstract class ClusterOperatorTest {
.withLabels(Constants.DEFAULT_LABELS) .withLabels(Constants.DEFAULT_LABELS)
.list() .list()
.getItems(); .getItems();
assertThat(kcDeployments.size()).isEqualTo(0); assertThat(kcDeployments.size()).isZero();
}); });
} }