Skip to content
Snippets Groups Projects
Commit 5e8cc5eb authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

change rolloutMode to waitForResourcesEnabled flag

parent af834343
No related branches found
No related tags found
1 merge request!261Wait until the resources of the predecessor resourceSet are ready
Pipeline #8315 failed
......@@ -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>
......
......@@ -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
......
......@@ -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
)
}
......
......@@ -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,
......
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")
}
}
......
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
......@@ -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()
......
......@@ -3,7 +3,7 @@ kind: benchmark
metadata:
name: example-benchmark
spec:
rolloutMode: "default"
waitForResourcesEnabled: false
sut:
resources:
- configMap:
......
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