@@ -58,6 +58,7 @@ public abstract class AbstractOperatorExtension
5858 protected Duration infrastructureTimeout ;
5959 protected final boolean oneNamespacePerClass ;
6060 protected final boolean preserveNamespaceOnError ;
61+ protected final boolean skipNamespaceDeletion ;
6162 protected final boolean waitForNamespaceDeletion ;
6263 protected final int namespaceDeleteTimeout = DEFAULT_NAMESPACE_DELETE_TIMEOUT ;
6364 protected final Function <ExtensionContext , String > namespaceNameSupplier ;
@@ -70,6 +71,7 @@ protected AbstractOperatorExtension(
7071 Duration infrastructureTimeout ,
7172 boolean oneNamespacePerClass ,
7273 boolean preserveNamespaceOnError ,
74+ boolean skipNamespaceDeletion ,
7375 boolean waitForNamespaceDeletion ,
7476 KubernetesClient kubernetesClient ,
7577 KubernetesClient infrastructureKubernetesClient ,
@@ -85,6 +87,7 @@ protected AbstractOperatorExtension(
8587 this .infrastructureTimeout = infrastructureTimeout ;
8688 this .oneNamespacePerClass = oneNamespacePerClass ;
8789 this .preserveNamespaceOnError = preserveNamespaceOnError ;
90+ this .skipNamespaceDeletion = skipNamespaceDeletion ;
8891 this .waitForNamespaceDeletion = waitForNamespaceDeletion ;
8992 this .namespaceNameSupplier = namespaceNameSupplier ;
9093 this .perClassNamespaceNameSupplier = perClassNamespaceNameSupplier ;
@@ -202,19 +205,22 @@ protected void after(ExtensionContext context) {
202205 if (preserveNamespaceOnError && context .getExecutionException ().isPresent ()) {
203206 LOGGER .info ("Preserving namespace {}" , namespace );
204207 } else {
208+ LOGGER .info ("Deleting infrastructure resources and operator in namespace {}" , namespace );
205209 infrastructureKubernetesClient .resourceList (infrastructure ).delete ();
206210 deleteOperator ();
207- LOGGER .info ("Deleting namespace {} and stopping operator" , namespace );
208- infrastructureKubernetesClient .namespaces ().withName (namespace ).delete ();
209- if (waitForNamespaceDeletion ) {
210- LOGGER .info ("Waiting for namespace {} to be deleted" , namespace );
211- Awaitility .await ("namespace deleted" )
212- .pollInterval (50 , TimeUnit .MILLISECONDS )
213- .atMost (namespaceDeleteTimeout , TimeUnit .SECONDS )
214- .until (
215- () ->
216- infrastructureKubernetesClient .namespaces ().withName (namespace ).get ()
217- == null );
211+ if (!skipNamespaceDeletion ) {
212+ LOGGER .info ("Deleting namespace {}" , namespace );
213+ infrastructureKubernetesClient .namespaces ().withName (namespace ).delete ();
214+ if (waitForNamespaceDeletion ) {
215+ LOGGER .info ("Waiting for namespace {} to be deleted" , namespace );
216+ Awaitility .await ("namespace deleted" )
217+ .pollInterval (50 , TimeUnit .MILLISECONDS )
218+ .atMost (namespaceDeleteTimeout , TimeUnit .SECONDS )
219+ .until (
220+ () ->
221+ infrastructureKubernetesClient .namespaces ().withName (namespace ).get ()
222+ == null );
223+ }
218224 }
219225 }
220226 }
@@ -229,6 +235,7 @@ public abstract static class AbstractBuilder<T extends AbstractBuilder<T>> {
229235 protected final List <HasMetadata > infrastructure ;
230236 protected Duration infrastructureTimeout ;
231237 protected boolean preserveNamespaceOnError ;
238+ protected boolean skipNamespaceDeletion ;
232239 protected boolean waitForNamespaceDeletion ;
233240 protected boolean oneNamespacePerClass ;
234241 protected int namespaceDeleteTimeout ;
@@ -245,6 +252,9 @@ protected AbstractBuilder() {
245252 this .preserveNamespaceOnError =
246253 Utils .getSystemPropertyOrEnvVar ("josdk.it.preserveNamespaceOnError" , false );
247254
255+ this .skipNamespaceDeletion =
256+ Utils .getSystemPropertyOrEnvVar ("josdk.it.skipNamespaceDeletion" , false );
257+
248258 this .waitForNamespaceDeletion =
249259 Utils .getSystemPropertyOrEnvVar ("josdk.it.waitForNamespaceDeletion" , true );
250260
@@ -261,6 +271,11 @@ public T preserveNamespaceOnError(boolean value) {
261271 return (T ) this ;
262272 }
263273
274+ public T skipNamespaceDeletion (boolean value ) {
275+ this .skipNamespaceDeletion = value ;
276+ return (T ) this ;
277+ }
278+
264279 public T waitForNamespaceDeletion (boolean value ) {
265280 this .waitForNamespaceDeletion = value ;
266281 return (T ) this ;
0 commit comments