diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java b/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java index 74fad20..ecd1d8c 100644 --- a/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java +++ b/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java @@ -419,26 +419,10 @@ public final void deleteResource(boolean async, T... res try { if (type == null) { client.getClient().resource(resource).delete(); - CompletableFuture c = CompletableFuture.runAsync(() -> - assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()), - String.format("Timed out deleting %s/%s in %s", resource.getKind(), - resource.getMetadata().getName(), resource.getMetadata().getNamespace()))); - if (async) { - waitExecutors.add(c); - } else { - CompletableFuture.allOf(c).join(); - } + decideDeleteWaitAsync(waitExecutors, async, resource); } else { type.delete(resource); - CompletableFuture c = CompletableFuture.runAsync(() -> - assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()), - String.format("Timed out deleting %s/%s in %s", resource.getKind(), - resource.getMetadata().getName(), resource.getMetadata().getNamespace()))); - if (async) { - waitExecutors.add(c); - } else { - CompletableFuture.allOf(c).join(); - } + decideDeleteWaitAsync(waitExecutors, async, resource); } } catch (Exception e) { if (resource.getMetadata().getNamespace() == null) { @@ -621,4 +605,17 @@ private void writeResourceAsYaml(HasMetadata resource) { throw new RuntimeException(e); } } + + private void decideDeleteWaitAsync(List> waitExecutors, + boolean async, T resource) { + CompletableFuture c = CompletableFuture.runAsync(() -> + assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()), + String.format("Timed out deleting %s/%s in %s", resource.getKind(), + resource.getMetadata().getName(), resource.getMetadata().getNamespace()))); + if (async) { + waitExecutors.add(c); + } else { + CompletableFuture.allOf(c).join(); + } + } }