Skip to content
Snippets Groups Projects
Commit 505cb2db authored by Lorenz Boguhn's avatar Lorenz Boguhn Committed by Sören Henning
Browse files

Block after deletion

for deployments in K8sManager.kt
parent 29e0d5dc
Branches
Tags
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!130Fix K8sManager + EnvVarPatcher,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
This commit is part of merge request !130. Comments created here will be created in the context of that merge request.
...@@ -39,16 +39,35 @@ class K8sManager(private val client: NamespacedKubernetesClient) { ...@@ -39,16 +39,35 @@ class K8sManager(private val client: NamespacedKubernetesClient) {
*/ */
fun remove(resource: KubernetesResource) { fun remove(resource: KubernetesResource) {
when (resource) { when (resource) {
is Deployment -> is Deployment -> {
val label = resource.spec.selector.matchLabels["app"]!!
this.client.apps().deployments().delete(resource) this.client.apps().deployments().delete(resource)
blockUntilDeleted(label)
}
is Service -> is Service ->
this.client.services().delete(resource) this.client.services().delete(resource)
is ConfigMap -> is ConfigMap ->
this.client.configMaps().delete(resource) this.client.configMaps().delete(resource)
is StatefulSet -> is StatefulSet -> {
val label = resource.spec.selector.matchLabels["app"]!!
this.client.apps().statefulSets().delete(resource) this.client.apps().statefulSets().delete(resource)
blockUntilDeleted(label)
}
is ServiceMonitorWrapper -> resource.delete(client) is ServiceMonitorWrapper -> resource.delete(client)
else -> throw IllegalArgumentException("Unknown Kubernetes resource.") 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)
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment