Skip to content
Snippets Groups Projects
Commit c76b3e4b authored by Lorenz Boguhn's avatar Lorenz Boguhn Committed by Lorenz Boguhn
Browse files

Fix ServiceMonitorWrapper.kt,

Also fix to correct usage of tread{} on the ShutdownHook
parent 6c3f7d76
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!120Add support for ServiceMonitors,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
......@@ -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
}
......@@ -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)
}
}
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment