From 687b96d42fccd10bde75516d66c33c6213210d81 Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Tue, 23 Feb 2021 20:32:23 +0100
Subject: [PATCH] Add a NodeSelectorPatcher

---
 .../theodolite/patcher/NodeSelectorPatcher.kt       | 13 +++++++++++++
 .../kotlin/theodolite/patcher/PatcherManager.kt     |  2 ++
 .../src/main/resources/yaml/testContext.yaml        | 12 ++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt
new file mode 100644
index 000000000..b6d75eb80
--- /dev/null
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt
@@ -0,0 +1,13 @@
+package theodolite.patcher
+
+import io.fabric8.kubernetes.api.model.KubernetesResource
+import io.fabric8.kubernetes.api.model.Service
+import io.fabric8.kubernetes.api.model.apps.Deployment
+
+class NodeSelectorPatcher(private val k8sResource: KubernetesResource, private val variableName: String): AbstractPatcher(k8sResource, variableName){
+    override fun <String> patch(value: String) {
+        if (k8sResource is Deployment) {
+                k8sResource.spec.template.spec.nodeSelector = mapOf(variableName to value as kotlin.String)
+        }
+    }
+}
\ No newline at end of file
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt
index f7875cf39..b3a63e2ad 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt
@@ -12,6 +12,8 @@ class PatcherManager {
             "EnvVarPatcher" -> EnvVarPatcher(k8sResources.filter { it.first == patcherDefinition.resource}.map { resource -> resource.second }[0],
                                 patcherDefinition.container,
                                 patcherDefinition.variableName)
+            "NodeSelectorPatcher" -> NodeSelectorPatcher(k8sResources.filter { it.first == patcherDefinition.resource }.map { resource -> resource.second }[0],
+                                patcherDefinition.variableName)
             else -> throw IllegalArgumentException("Patcher type ${patcherDefinition.type} not found")
         }
     }
diff --git a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml
index 289d15bbe..13c0ae375 100644
--- a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml
+++ b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml
@@ -29,4 +29,16 @@ configOverrides:
       container: "workload-generator"
       variableName: "KAFKA_SERVER"
     value: "localhost:9192"
+  - patcher:
+      type: "NodeSelectorPatcher"
+      resource: "workloadGenerator.yaml"
+      variableName: "env"
+    value: "prod"
+  - patcher:
+      type: "NodeSelectorPatcher"
+      resource: "aggregation-deployment.yaml"
+      variableName: "env"
+    value: "prod"
+
+
 
-- 
GitLab