diff --git a/theodolite-quarkus/config/example-benchmark-yaml-resource.yaml b/theodolite-quarkus/config/example-benchmark-yaml-resource.yaml index 60eb3bb9c31e3eab3e70f916b450372d56db4968..d507934fb87127748a1f6e22177f9dd9430f5f0b 100644 --- a/theodolite-quarkus/config/example-benchmark-yaml-resource.yaml +++ b/theodolite-quarkus/config/example-benchmark-yaml-resource.yaml @@ -19,6 +19,8 @@ loadTypes: resource: "uc1-load-generator-deployment.yaml" container: "workload-generator" variableName: "NUM_SENSORS" + - type: "NumSensorsLoadGeneratorReplicaPatcher" + resource: "uc1-load-generator-deployment.yaml" kafkaConfig: bootstrapServer: "theodolite-cp-kafka:9092" topics: diff --git a/theodolite-quarkus/config/example-operator-benchmark.yaml b/theodolite-quarkus/config/example-operator-benchmark.yaml index 419042fdd0b1e58fed4d402b4bb329d54602d23f..93b42e8690c3b9f432aea1c6711ee0118d14adb3 100644 --- a/theodolite-quarkus/config/example-operator-benchmark.yaml +++ b/theodolite-quarkus/config/example-operator-benchmark.yaml @@ -23,6 +23,8 @@ loadTypes: resource: "uc1-load-generator-deployment.yaml" container: "workload-generator" variableName: "NUM_SENSORS" + - type: "NumSensorsLoadGeneratorReplicaPatcher" + resource: "uc1-load-generator-deployment.yaml" kafkaConfig: bootstrapServer: "theodolite-cp-kafka:9092" topics: diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt index a9a7a4e385b73bde61014e75da3397a2bc9950e5..0de00fb5007b646240661310d037e34ef1ea1ae2 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt @@ -46,10 +46,10 @@ class KubernetesBenchmarkDeployment( * - Remove the [KubernetesResource]s. */ override fun teardown() { - KafkaLagExporterRemover(client).remove(LABEL) resources.forEach { kubernetesManager.remove(it) } kafkaController.removeTopics(this.topics.map { topic -> topic.name() }) + KafkaLagExporterRemover(client).remove(LABEL) } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt index ac2165303f083be066c4398e294e456f1d268dad..f8f7f9800ecb2b19f56d3dfe85c8f9cfc153b9f5 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) + } + } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt index 321fa9a945fade012a81ea4dbacb2c403e783411..e82a133b3e5439e72987f3db107f4e81a1d01cd5 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt @@ -30,7 +30,9 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) { result.all().get()// wait for the future object } catch (e: Exception) { + delete(newTopics.map { topic -> topic.name() }, kafkaAdmin) logger.warn { "Error during topic creation." } + logger.debug { e } logger.warn { "Will retry the topic creation after 2 seconds" } sleep(RETRY_TIME) retryCreation = true @@ -52,8 +54,13 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) { */ fun removeTopics(topics: List<String>) { val kafkaAdmin: AdminClient = AdminClient.create(this.kafkaConfig) + delete(topics, kafkaAdmin) + kafkaAdmin.close() + } + + private fun delete(topics: List<String>, kafkaAdmin: AdminClient) { var deleted = false - + while (!deleted) { try { val result = kafkaAdmin.deleteTopics(topics) @@ -80,6 +87,6 @@ class TopicManager(private val kafkaConfig: HashMap<String, Any>) { sleep(RETRY_TIME) } } - kafkaAdmin.close() } + } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt index 16bd9aa34127b79c97e8f9d195d4757145a3fa93..b640df1da2ca1c139bb5b02e9e42bad9e7d08d74 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt @@ -2,7 +2,6 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.Container import io.fabric8.kubernetes.api.model.EnvVar -import io.fabric8.kubernetes.api.model.EnvVarSource import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.apps.Deployment @@ -39,7 +38,9 @@ class EnvVarPatcher( val x = container.env.filter { envVar -> envVar.name == k } if (x.isEmpty()) { - val newVar = EnvVar(k, v, EnvVarSource()) + val newVar = EnvVar() + newVar.name = k + newVar.value = v container.env.add(newVar) } else { x.forEach {