From db04988beee9ef9419df8253bf0c1661e5b0fa87 Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Tue, 17 Aug 2021 09:46:13 +0200
Subject: [PATCH] small fixes, minor code changes

---
 .../theodolite/benchmark/ConfigMapResourceSet.kt    | 13 +++++++------
 .../theodolite/benchmark/FileSystemResourceSet.kt   | 11 +++++++----
 .../main/kotlin/theodolite/benchmark/ResourceSet.kt |  6 +++++-
 .../kotlin/theodolite/benchmark/ResourceSets.kt     |  9 ++++-----
 4 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt
index 3bfad3ccd..ac9e98980 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
 import io.fabric8.kubernetes.api.model.KubernetesResource
 import io.fabric8.kubernetes.client.DefaultKubernetesClient
 import io.fabric8.kubernetes.client.NamespacedKubernetesClient
+import io.quarkus.runtime.annotations.RegisterForReflection
 import mu.KotlinLogging
 import theodolite.k8s.resourceLoader.K8sResourceLoaderFromString
 import theodolite.util.YamlParserFromString
@@ -11,17 +12,17 @@ import theodolite.util.YamlParserFromString
 private val logger = KotlinLogging.logger {}
 private const val DEFAULT_NAMESPACE = "default"
 
+@RegisterForReflection
 @JsonDeserialize
-class ConfigMapResourceSet: ResourceSet {
+class ConfigMapResourceSet: ResourceSet, KubernetesResource {
     lateinit var configmap: String
     lateinit var files: List<String> // load all files, iff files is not set
-    private val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE
-    private val client: NamespacedKubernetesClient = DefaultKubernetesClient().inNamespace(namespace)
-    private val loader = K8sResourceLoaderFromString(client)
-
 
     @OptIn(ExperimentalStdlibApi::class)
     override fun getResourceSet(): List<Pair<String, KubernetesResource>> {
+        val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE
+        val client: NamespacedKubernetesClient = DefaultKubernetesClient().inNamespace(namespace)
+        val loader = K8sResourceLoaderFromString(client)
 
         var resources = client
             .configMaps()
@@ -42,7 +43,7 @@ class ConfigMapResourceSet: ResourceSet {
                 it) }
             .map {
                 Pair(
-                it.first,
+                it.second.key,
                 loader.loadK8sResource(it.first, it.second.value)) }
     }
 
diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt
index 6866fcf8a..dbedee6c8 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt
@@ -3,6 +3,7 @@ package theodolite.benchmark
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize
 import io.fabric8.kubernetes.api.model.KubernetesResource
 import io.fabric8.kubernetes.client.DefaultKubernetesClient
+import io.quarkus.runtime.annotations.RegisterForReflection
 import mu.KotlinLogging
 import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile
 import theodolite.util.DeploymentFailedException
@@ -12,13 +13,11 @@ import java.io.File
 private val logger = KotlinLogging.logger {}
 private const val DEFAULT_NAMESPACE = "default"
 
+@RegisterForReflection
 @JsonDeserialize
-class FileSystemResourceSet: ResourceSet {
+class FileSystemResourceSet: ResourceSet, KubernetesResource {
     lateinit var path: String
     lateinit var files: List<String>
-    private val parser = YamlParserFromFile()
-    private val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE
-    private val loader = K8sResourceLoaderFromFile(DefaultKubernetesClient().inNamespace(namespace))
 
     override fun getResourceSet(): List<Pair<String, KubernetesResource>> {
 
@@ -42,6 +41,10 @@ class FileSystemResourceSet: ResourceSet {
     }
 
     private fun loadSingleResource(resourceURL: String): Pair<String, KubernetesResource> {
+        val parser = YamlParserFromFile()
+        val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE
+        val loader = K8sResourceLoaderFromFile(DefaultKubernetesClient().inNamespace(namespace))
+
         val resourcePath = "$path/$resourceURL"
         val kind = parser.parse(resourcePath, HashMap<String, String>()::class.java)?.get("kind")!!
         val k8sResource = loader.loadK8sResource(kind, resourcePath)
diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSet.kt
index 2a0ce3966..974e06858 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSet.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSet.kt
@@ -1,8 +1,12 @@
 package theodolite.benchmark
 
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize
 import io.fabric8.kubernetes.api.model.KubernetesResource
+import io.quarkus.runtime.annotations.RegisterForReflection
 
-interface ResourceSet {
+@RegisterForReflection
+@JsonDeserialize
+interface ResourceSet: KubernetesResource {
 
     fun getResourceSet(): List<Pair<String, KubernetesResource>>
 }
\ No newline at end of file
diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt
index 1d5a2dc0e..f7b3dac80 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt
@@ -13,16 +13,16 @@ import theodolite.util.DeploymentFailedException
 @JsonInclude(JsonInclude.Include.NON_NULL)
 class ResourceSets: KubernetesResource {
     @JsonProperty("ConfigMapResourceSet")
-    val ConfigMapResourceSet: ConfigMapResourceSet? = null
+    lateinit var  ConfigMapResourceSet: ConfigMapResourceSet
 
     @JsonProperty("FileSystemResourceSet")
-    val FileSystemResourceSet: FileSystemResourceSet? = null
+    lateinit var FileSystemResourceSet: FileSystemResourceSet
 
     fun loadResourceSet(): List<Pair<String, KubernetesResource>> {
         return try {
-            if (ConfigMapResourceSet != null) {
+            if (::ConfigMapResourceSet.isInitialized) {
                 ConfigMapResourceSet.getResourceSet()
-            } else if (FileSystemResourceSet != null) {
+            } else if (::FileSystemResourceSet.isInitialized) {
                 FileSystemResourceSet.getResourceSet()
             } else {
                 throw  DeploymentFailedException("could not load resourceSet.")
@@ -30,6 +30,5 @@ class ResourceSets: KubernetesResource {
         } catch (e: Exception) {
             throw e
         }
-
     }
 }
\ No newline at end of file
-- 
GitLab