From 505cb2dbc14a31b0270b0f3684a2235b56ff67fb Mon Sep 17 00:00:00 2001 From: lorenz <stu203404@mail.uni-kiel.de> Date: Fri, 16 Apr 2021 15:35:43 +0200 Subject: [PATCH] Block after deletion for deployments in K8sManager.kt --- .../main/kotlin/theodolite/k8s/K8sManager.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt index ac2165303..f8f7f9800 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt @@ -39,16 +39,35 @@ class K8sManager(private val client: NamespacedKubernetesClient) { */ fun remove(resource: KubernetesResource) { when (resource) { - is Deployment -> + is Deployment -> { + val label = resource.spec.selector.matchLabels["app"]!! this.client.apps().deployments().delete(resource) + blockUntilDeleted(label) + } is Service -> this.client.services().delete(resource) is ConfigMap -> this.client.configMaps().delete(resource) - is StatefulSet -> + is StatefulSet -> { + val label = resource.spec.selector.matchLabels["app"]!! this.client.apps().statefulSets().delete(resource) + blockUntilDeleted(label) + } is ServiceMonitorWrapper -> resource.delete(client) else -> throw IllegalArgumentException("Unknown Kubernetes resource.") } } + + + private fun blockUntilDeleted(label: String) { + var deleted = false + do { + val pods = this.client.pods().withLabel(label).list().items + if (pods.isNullOrEmpty()) { + deleted = true + } + Thread.sleep(1000) + } while (!deleted) + } + } -- GitLab