From f05634da5f765362a5760fed6b0fc413651d4b48 Mon Sep 17 00:00:00 2001 From: lorenz <stu203404@mail.uni-kiel.de> Date: Sat, 27 Mar 2021 17:52:37 +0100 Subject: [PATCH] Add KubernetesRessourceConfiuration for theodolite --- .../infrastructure/kubernetes/rbac/role.yaml | 16 ++++++++- theodolite-quarkus/config/BenchmarkType.yaml | 2 +- .../config/thedolite-operator.yaml | 24 ++++++++++++++ .../src/main/docker/Dockerfile.jvm | 2 +- .../benchmark/KubernetesBenchmark.kt | 33 +++++++++++-------- .../KubernetesBenchmarkDeployment.kt | 9 +++-- 6 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 theodolite-quarkus/config/thedolite-operator.yaml diff --git a/execution/infrastructure/kubernetes/rbac/role.yaml b/execution/infrastructure/kubernetes/rbac/role.yaml index 84ba14a8b..a21fd554f 100644 --- a/execution/infrastructure/kubernetes/rbac/role.yaml +++ b/execution/infrastructure/kubernetes/rbac/role.yaml @@ -38,4 +38,18 @@ rules: verbs: - delete - list - - create \ No newline at end of file + - create + - apiGroups: + - theodolite.com + resources: + - executions + - benchmarks + verbs: + - delete + - list + - get + - create + - watch + - update + - patch + diff --git a/theodolite-quarkus/config/BenchmarkType.yaml b/theodolite-quarkus/config/BenchmarkType.yaml index 60eb3bb9c..42b1cd08d 100644 --- a/theodolite-quarkus/config/BenchmarkType.yaml +++ b/theodolite-quarkus/config/BenchmarkType.yaml @@ -20,7 +20,7 @@ loadTypes: container: "workload-generator" variableName: "NUM_SENSORS" kafkaConfig: - bootstrapServer: "theodolite-cp-kafka:9092" + bootstrapServer: "my-confluent-cp-kafka:9092" topics: - name: "input" numPartitions: 40 diff --git a/theodolite-quarkus/config/thedolite-operator.yaml b/theodolite-quarkus/config/thedolite-operator.yaml new file mode 100644 index 000000000..5059035b2 --- /dev/null +++ b/theodolite-quarkus/config/thedolite-operator.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: theodolite +spec: + selector: + matchLabels: + app: theodolite + replicas: 1 + template: + metadata: + labels: + app: theodolite + spec: + terminationGracePeriodSeconds: 0 + serviceAccountName: theodolite + containers: + - name: thedolite + image: lorenzboguhn/thedolite:latest + env: + - name: KUBECONFIG + value: "~/.kube/config" + - name: NAMESPACE + value: "default" \ No newline at end of file diff --git a/theodolite-quarkus/src/main/docker/Dockerfile.jvm b/theodolite-quarkus/src/main/docker/Dockerfile.jvm index 6733d5d44..232ab0397 100644 --- a/theodolite-quarkus/src/main/docker/Dockerfile.jvm +++ b/theodolite-quarkus/src/main/docker/Dockerfile.jvm @@ -41,7 +41,7 @@ RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security # Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. -ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dquarkus.package.main-class=TheodoliteOperator" COPY build/lib/* /deployments/lib/ COPY build/*-runner.jar /deployments/app.jar COPY config/ /deployments/config/ diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index dea845ec4..79b113936 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -20,17 +20,14 @@ class KubernetesBenchmark : Benchmark { lateinit var resourceTypes: List<TypeName> lateinit var loadTypes: List<TypeName> lateinit var kafkaConfig: KafkaConfig - lateinit var namespace: String - lateinit var path: String + val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE + val path = System.getenv("THEODOLITE_APP_RESOURCES") ?: "./config" + val client = DefaultKubernetesClient().inNamespace(namespace) private fun loadKubernetesResources(resources: List<String>): List<Pair<String, KubernetesResource>> { - //val path = "./../../../resources/main/yaml/" val parser = YamlParser() - namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE - logger.info { "Using $namespace as namespace." } - - val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace(namespace)) + val loader = K8sResourceLoader(client) return resources .map { resource -> val resourcePath = "$path/$resource" @@ -45,22 +42,32 @@ class KubernetesBenchmark : Benchmark { res: Resource, configurationOverrides: List<ConfigurationOverride?> ): BenchmarkDeployment { + logger.info { "Using $namespace as namespace." } + logger.info { "Using $path as resource path." } + val resources = loadKubernetesResources(this.appResource + this.loadGenResource) val patcherFactory = PatcherFactory() // patch the load dimension the resources - load.getType().forEach { patcherDefinition -> patcherFactory.createPatcher(patcherDefinition, resources).patch(load.get().toString()) } - res.getType().forEach{ patcherDefinition -> patcherFactory.createPatcher(patcherDefinition, resources).patch(res.get().toString()) } + load.getType().forEach { patcherDefinition -> + patcherFactory.createPatcher(patcherDefinition, resources).patch(load.get().toString()) + } + res.getType().forEach { patcherDefinition -> + patcherFactory.createPatcher(patcherDefinition, resources).patch(res.get().toString()) + } // Patch the given overrides - configurationOverrides.forEach { override -> override?.let { patcherFactory.createPatcher(it.patcher, resources).patch(override.value) } } - - + configurationOverrides.forEach { override -> + override?.let { + patcherFactory.createPatcher(it.patcher, resources).patch(override.value) + } + } return KubernetesBenchmarkDeployment( namespace = namespace, resources = resources.map { r -> r.second }, kafkaConfig = hashMapOf("bootstrap.servers" to kafkaConfig.bootstrapServer), - topics = kafkaConfig.getKafkaTopics() + topics = kafkaConfig.getKafkaTopics(), + client = client ) } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt index 238cb1707..8e4fce681 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt @@ -1,7 +1,7 @@ package theodolite.benchmark import io.fabric8.kubernetes.api.model.KubernetesResource -import io.fabric8.kubernetes.client.DefaultKubernetesClient +import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.quarkus.runtime.annotations.RegisterForReflection import org.apache.kafka.clients.admin.NewTopic import theodolite.k8s.K8sManager @@ -12,13 +12,12 @@ class KubernetesBenchmarkDeployment( val namespace: String, val resources: List<KubernetesResource>, private val kafkaConfig: HashMap<String, Any>, - private val topics: Collection<NewTopic> + private val topics: Collection<NewTopic>, + private val client: NamespacedKubernetesClient ) : BenchmarkDeployment { private val kafkaController = TopicManager(this.kafkaConfig) - private val kubernetesManager = K8sManager(DefaultKubernetesClient().inNamespace(namespace)) - + private val kubernetesManager = K8sManager(client) private val LABEL = "app.kubernetes.io/name=kafka-lag-exporter" - private val client = DefaultKubernetesClient().inNamespace(namespace) override fun setup() { kafkaController.createTopics(this.topics) -- GitLab