From 72edf7c9c6fb67b606a9ebbb2c7899796d41caf1 Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Wed, 5 Jan 2022 13:15:22 +0100
Subject: [PATCH] remove actions from examples and add them to the docs, small
 fixes

---
 docs/actions.md                               | 60 +++++++++++++++++++
 .../examples/operator/example-benchmark.yaml  | 15 -----
 .../KubernetesBenchmarkDeployment.kt          |  4 +-
 3 files changed, 62 insertions(+), 17 deletions(-)
 create mode 100644 docs/actions.md

diff --git a/docs/actions.md b/docs/actions.md
new file mode 100644
index 000000000..fefef96d7
--- /dev/null
+++ b/docs/actions.md
@@ -0,0 +1,60 @@
+## Infrastructure
+The necessary infrastructure for an execution can be defined in the benchmark manifests. The related resources are create *before* an execution is started, and removed *after* an execution is finished.
+
+### Example
+
+```yaml
+  infrastructure:
+    resources:
+      - configMap:
+          name: "example-configmap"
+          files:
+            - "uc1-kstreams-deployment.yaml"
+```
+
+## 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.
+
+### Example
+
+```yaml
+# For the system under test
+  sut:
+    resources: ...
+    beforeActions:
+      - selector:
+          pod:
+            matchLabels:
+              app: busybox1
+        exec:
+          command: ["touch", "test-file-sut"]
+          timeoutSeconds: 90
+    afterActions:
+      - selector:
+          pod:
+            matchLabels:
+              app: busybox1
+        exec:
+          command: [ "touch", "test-file-sut-after" ]
+          timeoutSeconds: 90
+
+# analog, for the load generator
+  loadGenerator:
+    resources: ... 
+    beforeActions:
+      - selector:
+          pod:
+            matchLabels:
+              app: busybox1
+        exec:
+          command: ["touch", "test-file-loadGen"]
+          timeoutSeconds: 90
+    afterActions:
+      - selector:
+          pod:
+            matchLabels:
+              app: busybox1
+        exec:
+          command: [ "touch", "test-file-loadGen-after" ]
+          timeoutSeconds: 90
+```
\ No newline at end of file
diff --git a/theodolite/examples/operator/example-benchmark.yaml b/theodolite/examples/operator/example-benchmark.yaml
index 84371d868..3452fff9c 100644
--- a/theodolite/examples/operator/example-benchmark.yaml
+++ b/theodolite/examples/operator/example-benchmark.yaml
@@ -3,26 +3,12 @@ kind: benchmark
 metadata:
   name: uc1-kstreams
 spec:
-  infrastructure:
-    resources:
-      - configMap:
-          name: "example-configmap"
-          files:
-            - "uc1-kstreams-deployment.yaml"
   sut:
     resources:
       - configMap:
          name: "example-configmap"
          files:
            - "uc1-kstreams-deployment.yaml"
-    beforeActions:
-      - selector:
-          pod:
-            matchLabels:
-              app: busybox1
-        exec:
-          command: ["touch", "test-folder"]
-          timeoutSeconds: 90
   loadGenerator:
     resources:
       - configMap:
@@ -30,7 +16,6 @@ spec:
          files:
             - uc1-load-generator-service.yaml
             - uc1-load-generator-deployment.yaml
-    beforeActions: []
   resourceTypes:
     - typeName: "Instances"
       patchers:
diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
index 21d5cb5bc..c9c75ab32 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
@@ -47,8 +47,6 @@ class KubernetesBenchmarkDeployment(
      */
     override fun setup() {
         sutBeforeActions.forEach { it.exec(client = client) }
-        loadGenBeforeActions.forEach { it.exec(client = client) }
-
         val kafkaTopics = this.topics.filter { !it.removeOnly }
             .map { NewTopic(it.name, it.numPartitions, it.replicationFactor) }
         kafkaController.createTopics(kafkaTopics)
@@ -56,6 +54,8 @@ class KubernetesBenchmarkDeployment(
         logger.info { "Wait ${this.loadGenerationDelay} seconds before starting the load generator." }
         Thread.sleep(Duration.ofSeconds(this.loadGenerationDelay).toMillis())
         loadGenResources.forEach { kubernetesManager.deploy(it) }
+        loadGenBeforeActions.forEach { it.exec(client = client) }
+
     }
 
     /**
-- 
GitLab