From 596a4647181e2a174e5bc9f1930b6282caaefc80 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Tue, 22 Oct 2024 09:36:16 +0200 Subject: [PATCH] Address comments v1 Signed-off-by: David Kornel --- .../resources/KubeResourceManager.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) 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(); + } + } }