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

enhance action docs, check also statefulsets in benchmarkstatechecker

parent dd35de42
No related branches found
No related tags found
1 merge request!201Introduce action commands
Pipeline #5832 passed
......@@ -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
......
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
......
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