diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/Shutdown.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/Shutdown.kt index 589dee1ac2e39d107794df1e3aa85ea56d6db92b..92aaef2923ed87e2bb2c3706ac4fc862538a222f 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/Shutdown.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/Shutdown.kt @@ -23,4 +23,4 @@ class Shutdown(private val benchmarkExecution: BenchmarkExecution, private val b deployment.teardown() logger.info { "Teardown completed" } } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt index eec7796e47485c1479407e72fb92d974fa67e59f..6bddea20c05fb5c0eb6a5a3bd60b3ec2c6b9bd5d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt @@ -28,13 +28,15 @@ class TheodoliteYamlExecutor { val benchmark = parser.parse(path = benchmarkPath, E = KubernetesBenchmark::class.java)!! - val shutdown = Shutdown(benchmarkExecution, benchmark) - Runtime.getRuntime().addShutdownHook(thread { shutdown.run()}) + // Add shutdown hook + // Use thread{} with start = false, else the thread will start right away + val shutdown = thread(start = false) { Shutdown(benchmarkExecution, benchmark).run() } + Runtime.getRuntime().addShutdownHook(shutdown) val executor = TheodoliteExecutor(benchmarkExecution, benchmark) executor.run() logger.info { "Theodolite finished" } - Runtime.getRuntime().removeShutdownHook(thread { shutdown.run()}) + Runtime.getRuntime().removeShutdownHook(shutdown) exitProcess(0) } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceMonitorWrapper.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceMonitorWrapper.kt index 7b1a0d0b32138bbda43ff28e306c8e64603a1310..4950cee225e103ff095def91de64471ec1894a79 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceMonitorWrapper.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceMonitorWrapper.kt @@ -1,22 +1,27 @@ package theodolite.k8s -import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.client.CustomResource import io.fabric8.kubernetes.client.NamespacedKubernetesClient import mu.KotlinLogging -import java.lang.Exception private val logger = KotlinLogging.logger {} -class ServiceMonitorWrapper(private val serviceMonitor: Map<String,String>): CustomResource() { +class ServiceMonitorWrapper(private val serviceMonitor: Map<String, String>) : CustomResource() { /** * Deploy a service monitor * * @param client a namespaced Kubernetes client which are used to deploy the CR object. + * + * @throws java.io.IOException if the resource could not be deployed. */ fun deploy(client: NamespacedKubernetesClient) { - val serviceMonitorContext = K8sContextFactory().create(api = "v1", scope = "Namespaced", group = "monitoring.coreos.com", plural = "servicemonitors") + val serviceMonitorContext = K8sContextFactory().create( + api = "v1", + scope = "Namespaced", + group = "monitoring.coreos.com", + plural = "servicemonitors" + ) client.customResource(serviceMonitorContext) .createOrReplace(client.configuration.namespace, this.serviceMonitor as Map<String, Any>) } @@ -27,16 +32,25 @@ class ServiceMonitorWrapper(private val serviceMonitor: Map<String,String>): Cus * @param client a namespaced Kubernetes client which are used to delete the CR object. */ fun delete(client: NamespacedKubernetesClient) { - val serviceMonitorContext = K8sContextFactory().create(api = "v1", scope = "Namespaced", group = "monitoring.coreos.com", plural = "servicemonitors") + val serviceMonitorContext = K8sContextFactory().create( + api = "v1", + scope = "Namespaced", + group = "monitoring.coreos.com", + plural = "servicemonitors" + ) try { - client.customResource(serviceMonitorContext).delete(client.configuration.namespace, this.getServiceMonitorName()) + client.customResource(serviceMonitorContext) + .delete(client.configuration.namespace, this.getServiceMonitorName()) } catch (e: Exception) { logger.warn { "Could not delete service monitor" } } } + /** + * @throws NullPointerException if name or metadata is null + */ private fun getServiceMonitorName(): String { - val smAsMap = this.serviceMonitor as Map<String, String> - return smAsMap["name"] !! + val smAsMap = this.serviceMonitor["metadata"]!! as Map<String, String> + return smAsMap["name"]!! } -} \ No newline at end of file +}