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

Merge branch 'theodolite-kotlin' of git.se.informatik.uni-kiel.de:she/spesb into theodolite-kotlin

parents c854a1fb 56921efe
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!108Feature/185 Make Paths Configurable,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
package theodolite.k8s
import io.fabric8.kubernetes.client.CustomResource
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext
/**
* Fabric8 handles custom resources as plain HashMaps. These need to be handled differently than normal
* Kubernetes resources. The K8sCustomResourceWrapper class provides a wrapper to deploy and delete
* custom resources in a uniform way.
*
* @property map custom resource as plain hashmap
* @constructor Create empty K8s custom resource wrapper
*/
class K8sCustomResourceWrapper(private val map : Map<String,String>) : CustomResource() {
/**
* Deploy a custom resource
*
* @param client a namespaced Kubernetes client which are used to deploy the CR object.
*/
fun deploy(client : NamespacedKubernetesClient){
val kind = this.map["kind"]
// Search the CustomResourceDefinition to which the CR Object belongs.
// This should be exactly one if the CRD is registered for Kubernetes, zero otherwise.
val crds = client.apiextensions().v1beta1().customResourceDefinitions().list()
crds.items
.filter { crd -> crd.toString().contains("kind=$kind") }
.map { crd -> CustomResourceDefinitionContext.fromCrd(crd) }
.forEach { context ->
client.customResource(context).createOrReplace(client.configuration.namespace,this.map as Map<String, Any>)
}
}
/**
* Delete a custom resource
*
* @param client a namespaced Kubernetes client which are used to delete the CR object.
*/
fun delete(client : NamespacedKubernetesClient){
val kind = this.map["kind"]
val metadata = this.map["metadata"] as HashMap<String,String>
val name = metadata["name"]
val crds = client.apiextensions().v1beta1().customResourceDefinitions().list()
crds.items
.filter { crd -> crd.toString().contains("kind=$kind") }
.map { crd -> CustomResourceDefinitionContext.fromCrd(crd) }
.forEach { context ->
client.customResource(context).delete(client.configuration.namespace,name) }
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.api.model.apps.StatefulSet
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
class K8sManager(private val client: NamespacedKubernetesClient) {
fun deploy(resource: KubernetesResource) {
when (resource) {
......@@ -18,6 +19,7 @@ class K8sManager(private val client: NamespacedKubernetesClient) {
this.client.configMaps().createOrReplace(resource)
is StatefulSet ->
this.client.apps().statefulSets().createOrReplace(resource)
is K8sCustomResourceWrapper -> resource.deploy(client)
else -> throw IllegalArgumentException("Unknown Kubernetes resource.")
}
}
......@@ -32,6 +34,7 @@ class K8sManager(private val client: NamespacedKubernetesClient) {
this.client.configMaps().delete(resource)
is StatefulSet ->
this.client.apps().statefulSets().delete(resource)
is K8sCustomResourceWrapper -> resource.delete(client)
else -> throw IllegalArgumentException("Unknown Kubernetes resource.")
}
}
......
......@@ -3,10 +3,10 @@ package theodolite.k8s
import io.fabric8.kubernetes.api.model.ConfigMap
import io.fabric8.kubernetes.api.model.KubernetesResource
import io.fabric8.kubernetes.api.model.Service
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition
import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import mu.KotlinLogging
import theodolite.util.YamlParser
private val logger = KotlinLogging.logger {}
......@@ -22,12 +22,12 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) {
}
/**
* Parses a Service from a service yaml
* Parses a CustomResource from a yaml
* @param path of the yaml file
* @return service from fabric8
* @return customResource from fabric8
*/
private fun loadServiceMonitor(path: String): CustomResourceDefinition {
return loadGenericResource(path) { x: String -> client.customResourceDefinitions().load(x).get() }
fun loadCustomResource(path: String): K8sCustomResourceWrapper {
return loadGenericResource(path) { x: String -> K8sCustomResourceWrapper(YamlParser().parse(path, HashMap<String, String>()::class.java)!!) }
}
/**
......@@ -73,9 +73,17 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) {
return when (kind) {
"Deployment" -> loadDeployment(path)
"Service" -> loadService(path)
"ServiceMonitor" -> loadServiceMonitor(path)
"ServiceMonitor" -> loadCustomResource(path)
"ConfigMap" -> loadConfigmap(path)
else -> throw IllegalArgumentException("Unknown resource with type $kind located in $path")
else -> {
logger.warn { "Try to load $kind from $path as Custom ressource" }
try{
loadCustomResource(path)
} catch (e:Exception){
logger.error { "Error during loading of unspecified CustomResource: $e" }
throw e
}
}
}
}
}
name: "Theodolite Test Context"
benchmark: "benchmarkType"
benchmark: "uc1-kstreams"
load:
loadType: "NumSensors"
loadValues:
......@@ -11,7 +11,7 @@ resources:
slos:
- sloType: "lag trend"
threshold: 1000
prometheusUrl: "http://localhost:32656"
prometheusUrl: "http://prometheus-operated:9090"
externalSloUrl: "http://localhost:80/evaluate-slope"
offset: 0
warmup: 0
......
name: "theodolite ist cool"
name: "uc1-kstreams"
appResource:
- "uc1-kstreams-deployment.yaml"
- "aggregation-service.yaml"
- "jmx-configmap.yaml"
- "uc1-service-monitor.yaml"
loadGenResource:
- "uc1-load-generator-deployment.yaml"
- "uc1-load-generator-service.yaml"
......@@ -19,7 +20,7 @@ loadTypes:
container: "workload-generator"
variableName: "NUM_SENSORS"
kafkaConfig:
bootstrapServer: "localhost:31290"
bootstrapServer: "theodolite-cp-kafka:9092"
topics:
- name: "input"
numPartitions: 40
......
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