From daf546cdc182943edeea87409634e4f213e4054a Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Tue, 29 Mar 2022 11:10:29 +0200 Subject: [PATCH] wait for inf resources before starting sut resources and wait for sut resources before starting load gen resources --- theodolite/crd/crd-benchmark.yaml | 6 +++ .../benchmark/KubernetesBenchmark.kt | 11 ++--- .../KubernetesBenchmarkDeployment.kt | 8 ++-- .../theodolite/benchmark/RolloutManager.kt | 42 +++++++++++++++++++ .../theodolite/benchmark/RolloutMode.kt | 10 +++++ 5 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt create mode 100644 theodolite/src/main/kotlin/theodolite/benchmark/RolloutMode.kt diff --git a/theodolite/crd/crd-benchmark.yaml b/theodolite/crd/crd-benchmark.yaml index c901e6136..9a728b22d 100644 --- a/theodolite/crd/crd-benchmark.yaml +++ b/theodolite/crd/crd-benchmark.yaml @@ -26,6 +26,12 @@ spec: description: This field exists only for technical reasons and should not be set by the user. The value of the field will be overwritten. type: string default: "" + rolloutMode: + type: string + default: "default" + enum: + - "no-waiting" + - "default" infrastructure: description: (Optional) A list of file names that reference Kubernetes resources that are deployed on the cluster to create the required infrastructure. type: object diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index d42c2ea3c..5ebd9ceea 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -37,6 +37,7 @@ private var DEFAULT_THEODOLITE_APP_RESOURCES = "./benchmark-resources" @RegisterForReflection class KubernetesBenchmark : KubernetesResource, Benchmark { lateinit var name: String + lateinit var rolloutMode: RolloutMode lateinit var resourceTypes: List<TypeName> lateinit var loadTypes: List<TypeName> var kafkaConfig: KafkaConfig? = null @@ -59,10 +60,8 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { override fun setupInfrastructure() { this.infrastructure.beforeActions.forEach { it.exec(client = client) } - val kubernetesManager = K8sManager(this.client) - loadKubernetesResources(this.infrastructure.resources) - .map{it.second} - .forEach { kubernetesManager.deploy(it) } + RolloutManager(rolloutMode, this.client) + .rollout(loadKubernetesResources(this.infrastructure.resources).map { it.second }) } override fun teardownInfrastructure() { @@ -124,7 +123,9 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { afterTeardownDelay = afterTeardownDelay, kafkaConfig = if (kafkaConfig != null) hashMapOf("bootstrap.servers" to kafkaConfig.bootstrapServer) else mapOf(), topics = kafkaConfig?.topics ?: listOf(), - client = this.client + client = this.client, + rolloutMode = rolloutMode + ) } diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt index 2b3cf0fa1..dcfdc0447 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt @@ -27,6 +27,7 @@ class KubernetesBenchmarkDeployment( private val sutAfterActions: List<Action>, private val loadGenBeforeActions: List<Action>, private val loadGenAfterActions: List<Action>, + private val rolloutMode: RolloutMode, val appResources: List<KubernetesResource>, val loadGenResources: List<KubernetesResource>, private val loadGenerationDelay: Long, @@ -46,19 +47,20 @@ class KubernetesBenchmarkDeployment( * - Deploy the needed resources. */ override fun setup() { + val rolloutManager = RolloutManager(rolloutMode, client) if (this.topics.isNotEmpty()) { val kafkaTopics = this.topics .filter { !it.removeOnly } .map { NewTopic(it.name, it.numPartitions, it.replicationFactor) } kafkaController.createTopics(kafkaTopics) } + sutBeforeActions.forEach { it.exec(client = client) } - appResources.forEach { kubernetesManager.deploy(it) } + rolloutManager.rollout(appResources) logger.info { "Wait ${this.loadGenerationDelay} seconds before starting the load generator." } Thread.sleep(Duration.ofSeconds(this.loadGenerationDelay).toMillis()) loadGenBeforeActions.forEach { it.exec(client = client) } - loadGenResources.forEach { kubernetesManager.deploy(it) } - + rolloutManager.rollout(loadGenResources) } /** diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt b/theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt new file mode 100644 index 000000000..fc29fac76 --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt @@ -0,0 +1,42 @@ +package theodolite.benchmark + +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.apps.DaemonSet +import io.fabric8.kubernetes.api.model.apps.Deployment +import io.fabric8.kubernetes.api.model.apps.ReplicaSet +import io.fabric8.kubernetes.api.model.apps.StatefulSet +import io.fabric8.kubernetes.client.NamespacedKubernetesClient +import theodolite.k8s.K8sManager + +private var SLEEP_TIME_MS = 500L + + +class RolloutManager(private val rolloutMode: RolloutMode, private val client: NamespacedKubernetesClient) { + + fun rollout(resources: List<KubernetesResource>) { + println("MODE IS: ${rolloutMode.value}") + resources + .forEach { K8sManager(client).deploy(it) } + + if (rolloutMode == RolloutMode.DEFAULT) { + resources + .forEach { + when (it) { + is Deployment -> waitFor { client.apps().deployments().withName(it.metadata.name).isReady } + is StatefulSet -> waitFor { client.apps().statefulSets().withName(it.metadata.name).isReady } + is DaemonSet -> waitFor { client.apps().daemonSets().withName(it.metadata.name).isReady } + is ReplicaSet -> waitFor { client.apps().replicaSets().withName(it.metadata.name).isReady } + } + } + } + } + + + private fun waitFor(f: () -> Boolean) { + while (!f()) { + Thread.sleep(SLEEP_TIME_MS) + println("wait for resource") + } + } + +} \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/RolloutMode.kt b/theodolite/src/main/kotlin/theodolite/benchmark/RolloutMode.kt new file mode 100644 index 000000000..052847c66 --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/benchmark/RolloutMode.kt @@ -0,0 +1,10 @@ +package theodolite.benchmark + +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.databind.annotation.JsonDeserialize + +@JsonDeserialize +enum class RolloutMode(@JsonValue val value: String) { + NONE("no-waiting"), + DEFAULT("default") +} \ No newline at end of file -- GitLab