From 6b2d51f844ee4d02db09ef5251f93b745a47df4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Henning?= <soeren.henning@email.uni-kiel.de> Date: Sat, 17 Apr 2021 16:58:56 +0200 Subject: [PATCH] Increasing K8s logging --- .../src/main/kotlin/theodolite/k8s/K8sManager.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt index f8f7f9800..09806e7b0 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt @@ -6,6 +6,9 @@ import io.fabric8.kubernetes.api.model.Service import io.fabric8.kubernetes.api.model.apps.Deployment import io.fabric8.kubernetes.api.model.apps.StatefulSet import io.fabric8.kubernetes.client.NamespacedKubernetesClient +import mu.KotlinLogging + +private val logger = KotlinLogging.logger {} /** * This class is used to deploy or remove different Kubernetes resources. @@ -42,7 +45,8 @@ class K8sManager(private val client: NamespacedKubernetesClient) { is Deployment -> { val label = resource.spec.selector.matchLabels["app"]!! this.client.apps().deployments().delete(resource) - blockUntilDeleted(label) + blockUntilPodDeleted(label) + logger.info { "Deployment '$resource' deleted." } } is Service -> this.client.services().delete(resource) @@ -51,7 +55,8 @@ class K8sManager(private val client: NamespacedKubernetesClient) { is StatefulSet -> { val label = resource.spec.selector.matchLabels["app"]!! this.client.apps().statefulSets().delete(resource) - blockUntilDeleted(label) + blockUntilPodDeleted(label) + logger.info { "StatefulSet '$resource' deleted." } } is ServiceMonitorWrapper -> resource.delete(client) else -> throw IllegalArgumentException("Unknown Kubernetes resource.") @@ -59,13 +64,14 @@ class K8sManager(private val client: NamespacedKubernetesClient) { } - private fun blockUntilDeleted(label: String) { + private fun blockUntilPodDeleted(podLabel: String) { var deleted = false do { - val pods = this.client.pods().withLabel(label).list().items + val pods = this.client.pods().withLabel(podLabel).list().items if (pods.isNullOrEmpty()) { deleted = true } + logger.info { "Wait for pods with label '$podLabel' to be deleted." } Thread.sleep(1000) } while (!deleted) } -- GitLab