From c2e866f13a9b5eaaa625522f7b902b965a20aee1 Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 7 May 2021 11:00:46 +0200 Subject: [PATCH] Allow to disable the project/namespace deletion on test failures --- README.md | 20 +++++++++++++++++++ .../test/configuration/PropertyLookup.java | 5 +++++ .../KubernetesExtensionBootstrap.java | 7 ++++++- .../OpenShiftExtensionBootstrap.java | 7 ++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2af84c3fa..3001a0bb2 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,16 @@ Use this Maven dependency: And now, we can write also scenarios to be run in OpenShift by adding the `@OpenShiftScenario`. +#### Enable/Disable Project Deletion on Failures + +By default, the framework will always delete the OpenShift project and, sometimes, it's useful to not delete +the OpenShift project on failures to troubleshooting purposes. For disabling the deletion on failures, we need to run the +test using: + +``` +mvn clean verify -Dts.openshift.delete.project.on.failure=false +``` + #### Deployment Strategies - **(Default) Using Build** @@ -513,6 +523,16 @@ public class KubernetesPingPongResourceIT { } ``` +#### Enable/Disable Namespace Deletion on Failures + +By default, the framework will always delete the Kubernetes namespace and, sometimes, it's useful to not delete +the Kubernetes namespace on failures to troubleshooting purposes. For disabling the deletion on failures, we need to run the +test using: + +``` +mvn clean verify -Dts.kubernetes.delete.namespace.on.failure=false +``` + #### Deployment Strategies - **(Default) Container Registry** diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java b/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java index 57a2964ad..b8e0ac084 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java @@ -53,4 +53,9 @@ public String get() { return defaultValue; } + + public Boolean getAsBoolean() { + String value = get(); + return Boolean.TRUE.toString().equalsIgnoreCase(value); + } } diff --git a/quarkus-test-kubernetes/src/main/java/io/quarkus/test/bootstrap/KubernetesExtensionBootstrap.java b/quarkus-test-kubernetes/src/main/java/io/quarkus/test/bootstrap/KubernetesExtensionBootstrap.java index 2bceb8e3f..c7ce6c397 100644 --- a/quarkus-test-kubernetes/src/main/java/io/quarkus/test/bootstrap/KubernetesExtensionBootstrap.java +++ b/quarkus-test-kubernetes/src/main/java/io/quarkus/test/bootstrap/KubernetesExtensionBootstrap.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import io.quarkus.test.bootstrap.inject.KubectlClient; +import io.quarkus.test.configuration.PropertyLookup; import io.quarkus.test.logging.Log; import io.quarkus.test.scenarios.KubernetesScenario; import io.quarkus.test.utils.FileUtils; @@ -15,6 +16,8 @@ public class KubernetesExtensionBootstrap implements ExtensionBootstrap { public static final String CLIENT = "kubectl-client"; + private static final PropertyLookup DELETE_ON_FAIL = new PropertyLookup("ts.kubernetes.delete.namespace.on.failure", + Boolean.TRUE.toString()); private KubectlClient client; @@ -30,7 +33,9 @@ public void beforeAll(ExtensionContext context) { @Override public void afterAll(ExtensionContext context) { - client.deleteNamespace(); + if (DELETE_ON_FAIL.getAsBoolean()) { + client.deleteNamespace(); + } } @Override diff --git a/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/OpenShiftExtensionBootstrap.java b/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/OpenShiftExtensionBootstrap.java index eee9a9bd1..c42b9bc6b 100644 --- a/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/OpenShiftExtensionBootstrap.java +++ b/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/OpenShiftExtensionBootstrap.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import io.quarkus.test.bootstrap.inject.OpenShiftClient; +import io.quarkus.test.configuration.PropertyLookup; import io.quarkus.test.logging.Log; import io.quarkus.test.scenarios.OpenShiftScenario; import io.quarkus.test.utils.FileUtils; @@ -15,6 +16,8 @@ public class OpenShiftExtensionBootstrap implements ExtensionBootstrap { public static final String CLIENT = "openshift-client"; + private static final PropertyLookup DELETE_ON_FAIL = new PropertyLookup("ts.openshift.delete.project.on.failure", + Boolean.TRUE.toString()); private OpenShiftClient client; @@ -30,7 +33,9 @@ public void beforeAll(ExtensionContext context) { @Override public void afterAll(ExtensionContext context) { - client.deleteProject(); + if (DELETE_ON_FAIL.getAsBoolean()) { + client.deleteProject(); + } } @Override