diff --git a/docs/api-reference/crds.md b/docs/api-reference/crds.md index 3dd872522c7dd44013ad3c18eb89802df43c6d54..2214691f2015a327f0c0be2a4570f3db58a5a7f6 100644 --- a/docs/api-reference/crds.md +++ b/docs/api-reference/crds.md @@ -138,13 +138,12 @@ Resource Types: </td> <td>false</td> </tr><tr> - <td><b>rolloutMode</b></td> - <td>enum</td> + <td><b>waitForResourcesEnabled</b></td> + <td>boolean</td> <td> + If true, Theodolite waits to create the resource for the SUT until the infrastructure resources are ready, and analogously, Theodolite waits to create the load-gen resource until the resources of the SUT are ready.<br/> <br/> - <br/> - <i>Enum</i>: no-waiting, default<br/> - <i>Default</i>: default<br/> + <i>Default</i>: false<br/> </td> <td>false</td> </tr><tr> diff --git a/theodolite/crd/crd-benchmark.yaml b/theodolite/crd/crd-benchmark.yaml index 9a728b22d65112376d664c921b2cde9107db674f..d2418ee005e2c0168254a9423b9c383ace2d3ca7 100644 --- a/theodolite/crd/crd-benchmark.yaml +++ b/theodolite/crd/crd-benchmark.yaml @@ -26,12 +26,10 @@ 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" + waitForResourcesEnabled: + description: If true, Theodolite waits to create the resource for the SUT until the infrastructure resources are ready, and analogously, Theodolite waits to create the load-gen resource until the resources of the SUT are ready. + type: boolean + default: false 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 0abe824324f3b461cf6232e610c60efb2017890d..6e8048547fb857d4c659e32885dc46ea1b1c9ae4 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -10,6 +10,7 @@ import mu.KotlinLogging import theodolite.k8s.K8sManager import theodolite.patcher.PatcherFactory import theodolite.util.* +import kotlin.properties.Delegates private val logger = KotlinLogging.logger {} @@ -37,7 +38,7 @@ private var DEFAULT_THEODOLITE_APP_RESOURCES = "./benchmark-resources" @RegisterForReflection class KubernetesBenchmark : KubernetesResource, Benchmark { lateinit var name: String - lateinit var rolloutMode: RolloutMode + var waitForResourcesEnabled = false lateinit var resourceTypes: List<TypeName> lateinit var loadTypes: List<TypeName> var kafkaConfig: KafkaConfig? = null @@ -65,7 +66,7 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { override fun setupInfrastructure() { this.infrastructure.beforeActions.forEach { it.exec(client = client) } - RolloutManager(rolloutMode, this.client) + RolloutManager(waitForResourcesEnabled, this.client) .rollout(loadResources(this.infrastructure.resources).map { it.second }) } @@ -129,7 +130,7 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { kafkaConfig = if (kafkaConfig != null) mapOf("bootstrap.servers" to kafkaConfig.bootstrapServer) else mapOf(), topics = kafkaConfig?.topics ?: listOf(), client = this.client, - rolloutMode = rolloutMode + rolloutMode = waitForResourcesEnabled ) } diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt index d6ba65b37b656d20754d33b2916191859528fa98..1d7b22233c084625cf16ca7194c76c14601bbaad 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt @@ -28,7 +28,7 @@ class KubernetesBenchmarkDeployment( private val sutAfterActions: List<Action>, private val loadGenBeforeActions: List<Action>, private val loadGenAfterActions: List<Action>, - private val rolloutMode: RolloutMode, + private val rolloutMode: Boolean, val appResources: List<HasMetadata>, val loadGenResources: List<HasMetadata>, private val loadGenerationDelay: Long, diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt b/theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt index 203ced6518572aeda10f9e8689307f97cd5178b8..f282fb27971218754a0e35801342efc83837b64b 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/RolloutManager.kt @@ -1,23 +1,25 @@ package theodolite.benchmark import io.fabric8.kubernetes.api.model.HasMetadata +import io.fabric8.kubernetes.api.model.Pod 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.api.model.batch.v1.Job 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) { +class RolloutManager(private val blockUntilResourcesReady: Boolean, private val client: NamespacedKubernetesClient) { fun rollout(resources: List<HasMetadata>) { resources .forEach { K8sManager(client).deploy(it) } - if (rolloutMode == RolloutMode.DEFAULT) { + if (blockUntilResourcesReady) { resources .forEach { when (it) { @@ -25,16 +27,15 @@ class RolloutManager(private val rolloutMode: RolloutMode, private val client: N 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 } + is Job -> waitFor { client.batch().v1().cronjobs().withName(it.metadata.name).isReady } } } } } - - private fun waitFor(f: () -> Boolean) { - while (!f()) { + private fun waitFor(isResourceReady: () -> Boolean) { + while (!isResourceReady()) { Thread.sleep(SLEEP_TIME_MS) - println("wait for resource") } } diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/RolloutMode.kt b/theodolite/src/main/kotlin/theodolite/benchmark/RolloutMode.kt deleted file mode 100644 index 052847c66880cebbb6a1ffa91dce91d87afa325b..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/benchmark/RolloutMode.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 diff --git a/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt b/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt index bad9773d349c4daf7b697e8127c74a8aa9442bb8..d6841429166d1549e84ad27887fbf0cba86b174d 100644 --- a/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt +++ b/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt @@ -2,7 +2,6 @@ package theodolite.execution.operator import theodolite.benchmark.KubernetesBenchmark import theodolite.benchmark.Resources -import theodolite.benchmark.RolloutMode import theodolite.model.crd.BenchmarkCRD import theodolite.util.KafkaConfig @@ -26,7 +25,7 @@ class BenchmarkCRDummy(name: String) { benchmarkCR.metadata.name = name benchmarkCR.kind = "Benchmark" benchmarkCR.apiVersion = "v1" - benchmark.rolloutMode = RolloutMode.DEFAULT + benchmark.waitForResourcesEnabled = false benchmark.infrastructure = Resources() benchmark.sut = Resources() diff --git a/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml b/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml index e45ecb2227d7724ae45d3bb96c244306678b5291..102a6a249ab06301396eaf375e7bd2590b334b22 100644 --- a/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml +++ b/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml @@ -3,7 +3,7 @@ kind: benchmark metadata: name: example-benchmark spec: - rolloutMode: "default" + waitForResourcesEnabled: false sut: resources: - configMap: