diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index 1e2d9a2e675bee3817c493e5afc89333ca508ed8..5af641d015b10b9ed27fc7fd2006c05b24dae216 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -1,6 +1,7 @@ package theodolite.benchmark import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.client.CustomResource import io.fabric8.kubernetes.client.DefaultKubernetesClient import mu.KotlinLogging import theodolite.k8s.K8sResourceLoader @@ -11,7 +12,8 @@ private val logger = KotlinLogging.logger {} private var DEFAULT_NAMESPACE = "default" -class KubernetesBenchmark : Benchmark { + +class KubernetesBenchmark : Benchmark , CustomResource() { lateinit var name: String lateinit var appResource: List<String> lateinit var loadGenResource: List<String> diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkList.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkList.kt new file mode 100644 index 0000000000000000000000000000000000000000..06d0d268a832a85e71e440534a8e8204ebfb324a --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkList.kt @@ -0,0 +1,6 @@ +package theodolite.benchmark + +import io.fabric8.kubernetes.client.CustomResourceList + +class KubernetesBenchmarkList : CustomResourceList<KubernetesBenchmark>() { +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteController.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteController.kt new file mode 100644 index 0000000000000000000000000000000000000000..b03171bb737aea191c38be758aa2b3151fa95157 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteController.kt @@ -0,0 +1,95 @@ +package theodolite.execution + +import io.fabric8.kubernetes.client.NamespacedKubernetesClient +import io.fabric8.kubernetes.client.informers.ResourceEventHandler +import io.fabric8.kubernetes.client.informers.SharedInformer +import mu.KotlinLogging +import theodolite.benchmark.BenchmarkExecution +import theodolite.benchmark.KubernetesBenchmark + +private val logger = KotlinLogging.logger {} + + +class TheodoliteController(val client : NamespacedKubernetesClient, + val informerBenchmarkExecution: SharedInformer<BenchmarkExecution>, + val informerBenchmarkType : SharedInformer<KubernetesBenchmark> ) { + + var execution : BenchmarkExecution? = null + var benchmarkType : KubernetesBenchmark? = null + + var executor : TheodoliteExecutor? = null + + var updated : Boolean = true + + public fun create(){ + + informerBenchmarkExecution.addEventHandler(object : ResourceEventHandler<BenchmarkExecution> { + override fun onAdd(webServer: BenchmarkExecution) { + execution = webServer + } + + override fun onUpdate(webServer: BenchmarkExecution, newWebServer: BenchmarkExecution) { + println("hello there update") + execution = newWebServer + updated = true + shutdown() + + } + + override fun onDelete(webServer: BenchmarkExecution, b: Boolean) { + println("delted") + shutdown() + } + }) + + informerBenchmarkType.addEventHandler(object : ResourceEventHandler<KubernetesBenchmark> { + override fun onAdd(webServer: KubernetesBenchmark) { + benchmarkType = webServer + println("hello there add") + println(webServer.name) + } + + override fun onUpdate(webServer: KubernetesBenchmark, newWebServer: KubernetesBenchmark) { + benchmarkType = newWebServer + println("hello there update") + updated = true + shutdown() + + + } + + override fun onDelete(webServer: KubernetesBenchmark, b: Boolean) { + println("delted") + println(webServer.name) + shutdown() + } + }) + } + + fun run(){ + while (true){ + try { + reconcile() + } + catch (e: InterruptedException){ + logger.error{"$e "} + } + } + } + + @Synchronized + private fun reconcile() { + val localExecution = this.execution + val localType = this.benchmarkType + if(localType is KubernetesBenchmark && localExecution is BenchmarkExecution && updated){ + + executor = TheodoliteExecutor(config= localExecution,kubernetesBenchmark = localType) + executor!!.run() + updated = false + } + } + + private fun shutdown(){ + + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteOperator.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteOperator.kt index 549b7723021a6993afff923675ac3852ff373490..9109d1246c01b47779b982bf7910f75dfc33470e 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteOperator.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteOperator.kt @@ -2,15 +2,12 @@ package theodolite.execution import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext -import io.fabric8.kubernetes.client.informers.ResourceEventHandler import io.quarkus.runtime.annotations.QuarkusMain import mu.KotlinLogging import theodolite.benchmark.* import io.fabric8.kubernetes.internal.KubernetesDeserializer - - private var DEFAULT_NAMESPACE = "default" private val logger = KotlinLogging.logger {} @@ -19,8 +16,8 @@ object TheodoliteCRDExecutor { @JvmStatic fun main(args: Array<String>) { -// val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE -// logger.info { "Using $namespace as namespace." } + val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE + logger.info { "Using $namespace as namespace." } val client = DefaultKubernetesClient().inNamespace("default") @@ -31,42 +28,46 @@ object TheodoliteCRDExecutor { BenchmarkExecution::class.java ) + KubernetesDeserializer.registerCustomKind( + "demo.k8s.io/v1alpha1", + "Benchmarktype", + KubernetesBenchmark::class.java + ) - val context = CustomResourceDefinitionContext.Builder() + val ExececutionContext = CustomResourceDefinitionContext.Builder() .withVersion("v1alpha1") .withScope("Namespaced") .withGroup("demo.k8s.io") .withPlural("benchmarkexecutions") .build() + val TypeContext = CustomResourceDefinitionContext.Builder() + .withVersion("v1alpha1") + .withScope("Namespaced") + .withGroup("demo.k8s.io") + .withPlural("benchmarktypes") + .build() + val informerFactory = client.informers() - val x = informerFactory.sharedIndexInformerForCustomResource(context, BenchmarkExecution::class.java, + val informerBenchmarkExecution = informerFactory.sharedIndexInformerForCustomResource(ExececutionContext, BenchmarkExecution::class.java, BenchmarkExecutionList::class.java,10 * 60 * 1000.toLong()) + val informerBenchmarkType = informerFactory.sharedIndexInformerForCustomResource(TypeContext, KubernetesBenchmark::class.java, + KubernetesBenchmarkList::class.java,10 * 60 * 1000.toLong()) - x.addEventHandler(object : ResourceEventHandler<BenchmarkExecution> { - override fun onAdd(webServer: BenchmarkExecution) { - println("hello there add") - println(webServer.name) - } - override fun onUpdate(webServer: BenchmarkExecution, newWebServer: BenchmarkExecution) { - println("hello there update") - } - override fun onDelete(webServer: BenchmarkExecution, b: Boolean) { - println("delted") - println(webServer.name) - } - }) - - informerFactory.startAllRegisteredInformers() + val controller = TheodoliteController(client = client, + informerBenchmarkExecution = informerBenchmarkExecution, + informerBenchmarkType = informerBenchmarkType) + controller.create() + informerFactory.startAllRegisteredInformers() - //println(client.apiextensions().v1beta1().customResourceDefinitions().list()) + controller.run() //exitProcess(0) } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt index 8c529e3d8e793d96819afe78008c663e76504911..2a54dc3b16abe6171eb90a99d87dab4810ab2333 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt @@ -1,8 +1,10 @@ package theodolite.util +import com.fasterxml.jackson.databind.annotation.JsonDeserialize import org.apache.kafka.clients.admin.NewTopic import kotlin.properties.Delegates +@JsonDeserialize class KafkaConfig { lateinit var bootstrapServer: String lateinit var topics: List<TopicWrapper> diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt index 3568a355edbddd3b29e6d934deecb923518af3df..0ee8a18982ae2a59d022a5c45bfa9c843db6a5f0 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt @@ -1,5 +1,8 @@ package theodolite.util +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +@JsonDeserialize class TypeName { lateinit var typeName: String lateinit var patchers: List<PatcherDefinition> diff --git a/theodolite-quarkus/src/main/resources/Operator/BenchmarkExecution.yaml b/theodolite-quarkus/src/main/resources/Operator/BenchmarkExecution.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6caff74a53059fd888c3a0cc790c6d3de99b9a89 --- /dev/null +++ b/theodolite-quarkus/src/main/resources/Operator/BenchmarkExecution.yaml @@ -0,0 +1,27 @@ +apiVersion: demo.k8s.io/v1alpha1 +kind: Benchmarkexecutions +metadata: + name: example-webserver +name: "Theodolite Test Context" +benchmark: "benchmarkType" +load: + loadType: "NumSensors" + loadValues: + - 50000 +resources: + resourceType: "Instances" + resourceValues: + - 1 +slos: + - sloType: "lag trend" + threshold: 1000 + prometheusUrl: "http://localhost:32656" + externalSloUrl: "http://localhost:80/evaluate-slope" + offset: 0 + warmup: 0 +execution: + strategy: "LinearSearch" + duration: 60 + repetitions: 1 + restrictions: + - "LowerBound" \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/Operator/BenchmarktypeCrd.yaml b/theodolite-quarkus/src/main/resources/Operator/BenchmarktypeCrd.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e58eca7b436ea757e7d5b0d058d8a61de2d9709d --- /dev/null +++ b/theodolite-quarkus/src/main/resources/Operator/BenchmarktypeCrd.yaml @@ -0,0 +1,13 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: benchmarktypes.demo.k8s.io +spec: + group: demo.k8s.io + version: v1alpha1 + names: + kind: Benchmarktype + plural: benchmarktypes + scope: Namespaced + subresources: + status: {} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/testcrd.yaml b/theodolite-quarkus/src/main/resources/Operator/ExecutionCrd.yaml similarity index 100% rename from theodolite-quarkus/src/main/resources/yaml/testcrd.yaml rename to theodolite-quarkus/src/main/resources/Operator/ExecutionCrd.yaml diff --git a/theodolite-quarkus/src/main/resources/Operator/benchmarktype.yaml b/theodolite-quarkus/src/main/resources/Operator/benchmarktype.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a57aa3a9c6a10019068aea58538531b76d2bb0bf --- /dev/null +++ b/theodolite-quarkus/src/main/resources/Operator/benchmarktype.yaml @@ -0,0 +1,31 @@ +apiVersion: demo.k8s.io/v1alpha1 +kind: Benchmarktype +metadata: + name: example-webserver +name: "theodolite ist cool" +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" +resourceTypes: + - typeName: "Instances" + patchers: + - type: "ReplicaPatcher" + resource: "uc1-kstreams-deployment.yaml" +loadTypes: + - typeName: "NumSensors" + patchers: + - type: "EnvVarPatcher" + resource: "uc1-load-generator-deployment.yaml" + container: "workload-generator" + variableName: "NUM_SENSORS" +kafkaConfig: + bootstrapServer: "localhost:31290" + topics: + - name: "input" + numPartitions: 40 + replicationFactor: 1 \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRD.yaml b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRD.yaml deleted file mode 100644 index a91d123628a03bb7fd82821d6f34d7bf1239c154..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRD.yaml +++ /dev/null @@ -1,46 +0,0 @@ -name: "Theodolite Test Context" -benchmark: "benchmarkType" -load: - loadType: "NumSensors" - loadValues: - - 50000 -resources: - resourceType: "Instances" - resourceValues: - - 1 -slos: - - sloType: "lag trend" - threshold: 1000 - prometheusUrl: "http://localhost:32656" - externalSloUrl: "http://localhost:80/evaluate-slope" - offset: 0 - warmup: 0 -execution: - strategy: "LinearSearch" - duration: 60 - repetitions: 1 - restrictions: - - "LowerBound" -configOverrides: - - patcher: - type: "NodeSelectorPatcher" - resource: "uc1-load-generator-deployment.yaml" - variableName: "env" - value: "prod" - - patcher: - type: "NodeSelectorPatcher" - resource: "uc1-kstreams-deployment.yaml" - variableName: "env" - value: "prod" - - patcher: - type: "ResourceLimitPatcher" - resource: "uc1-kstreams-deployment.yaml" - container: "uc-application" - variableName: "cpu" - value: "1000m" - - patcher: - type: "ResourceLimitPatcher" - resource: "uc1-kstreams-deployment.yaml" - container: "uc-application" - variableName: "memory" - value: "2Gi" \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRDShema.yaml b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRDShema.yaml deleted file mode 100644 index f7e0d1ec90d4b7e33fae5889823335ae63c20f51..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRDShema.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: examples.theodolite.com -spec: - group: theodolite.com - scope: Namespaced - versions: - - name: v1alpha1 - served: true - storage: true - schema: - openAPIV3Schema: - type: object - properties: - spec: - type : object - names: - kind: BenchmarkExecution - listKind: BenchmarkExecutionList - plural: examples - singular: example diff --git a/theodolite-quarkus/src/main/resources/yaml/resource.yaml b/theodolite-quarkus/src/main/resources/yaml/resource.yaml deleted file mode 100644 index 15b45b191a98a5e375e2f27596489c9ffb06d228..0000000000000000000000000000000000000000 --- a/theodolite-quarkus/src/main/resources/yaml/resource.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: demo.k8s.io/v1alpha1 -kind: Benchmarkexecutions -metadata: - name: aids-webserver -spec: - message: "Theodolite Test Context" \ No newline at end of file