From 10fa011fc6fe15226ccc301a55e71b30390df8e9 Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Wed, 5 Jan 2022 21:41:40 +0100 Subject: [PATCH] enhance action docs, check also statefulsets in benchmarkstatechecker --- docs/actions.md | 2 + .../operator/BenchmarkStateChecker.kt | 47 ++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/docs/actions.md b/docs/actions.md index fefef96d7..8092fddb0 100644 --- a/docs/actions.md +++ b/docs/actions.md @@ -15,6 +15,8 @@ The necessary infrastructure for an execution can be defined in the benchmark ma ## Action Commands Theodolite allows to execute commands on running pods (similar to the `kubectl exec -it <pod-name> -- <command>` command). This commands can be run either before (via so called `beforeActions`) or after (via so called `afterActions`) an experiment is executed. +Theodolite checks if all required pods are available for the specified actions (i.e. the pods must either be defined as infrastructure or already deployed in the cluster). If not all pods/resources are available, the benchmark will not be set as `Ready`. Consequently, an action cannot be executed on a pod that is defined as an SUT or loadGen resource. + ### Example ```yaml diff --git a/theodolite/src/main/kotlin/theodolite/execution/operator/BenchmarkStateChecker.kt b/theodolite/src/main/kotlin/theodolite/execution/operator/BenchmarkStateChecker.kt index e21366ce6..959b04a8e 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/operator/BenchmarkStateChecker.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/operator/BenchmarkStateChecker.kt @@ -1,6 +1,7 @@ package theodolite.execution.operator import io.fabric8.kubernetes.api.model.apps.Deployment +import io.fabric8.kubernetes.api.model.apps.StatefulSet import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.fabric8.kubernetes.client.dsl.MixedOperation import io.fabric8.kubernetes.client.dsl.Resource @@ -129,21 +130,41 @@ class BenchmarkStateChecker( */ fun checkIfResourceIsInfrastructure(resourcesSets: List<ResourceSets>, selector: ActionSelector): Boolean { val resources = resourcesSets.flatMap { it.loadResourceSet(this.client) } + if (resources.isEmpty()) { + return false + } - return if (resources.isEmpty()) { - false - } else { - resources.map { it.second } - .filterIsInstance<Deployment>() - .filter { it.metadata.labels.containsMatchLabels(selector.pod.matchLabels) } - .any { - if (selector.container.isNotEmpty()) { - it.spec.template.spec.containers.map { it.name }.contains(selector.container) - } else { - true - } + var podExist = resources.map { it.second } + .filterIsInstance<Deployment>() + .filter { it.metadata.labels.containsMatchLabels(selector.pod.matchLabels) } + .any { + if (selector.container.isNotEmpty()) { + it.spec.template.spec.containers.map { it.name }.contains(selector.container) + } else { + true } + } + + if (podExist) { + return true } + + podExist = resources.map { it.second } + .filterIsInstance<StatefulSet>() + .filter { it.metadata.labels.containsMatchLabels(selector.pod.matchLabels) } + .any { + if (selector.container.isNotEmpty()) { + it.spec.template.spec.containers.map { it.name }.contains(selector.container) + } else { + true + } + } + + if (podExist) { + return true + } + + return false } /** @@ -169,7 +190,7 @@ class BenchmarkStateChecker( } } -private fun <K, V> MutableMap<K, V>.containsMatchLabels(matchLabels: MutableMap<V, V>) : Boolean { +private fun <K, V> MutableMap<K, V>.containsMatchLabels(matchLabels: MutableMap<V, V>): Boolean { for (kv in matchLabels) { if (kv.value != this[kv.key as K]) { return false -- GitLab