From ae746bf24fe4939e2253b9894e6f20d81a51e09e Mon Sep 17 00:00:00 2001
From: lorenz <stu203404@mail.uni-kiel.de>
Date: Sat, 23 Jan 2021 15:02:12 +0100
Subject: [PATCH] Add generic load method

---
 .../src/main/kotlin/theodolite/YamlLoader.kt  | 31 +++++++++++++++++--
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt b/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt
index ef3d16c32..253710e39 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt
@@ -1,12 +1,18 @@
 package theodolite
 
 import io.fabric8.kubernetes.api.model.Service
+import io.fabric8.kubernetes.api.model.apps.Deployment
 import io.fabric8.kubernetes.client.NamespacedKubernetesClient
 import mu.KotlinLogging
 private val logger = KotlinLogging.logger {}
 
 class YamlLoader(client: NamespacedKubernetesClient) {
-    var client = client
+    lateinit var client: NamespacedKubernetesClient
+
+    init{
+         this.client = client
+    }
+
 
     fun loadService(path: String): Service? {
 
@@ -14,12 +20,31 @@ class YamlLoader(client: NamespacedKubernetesClient) {
 
         try {
             service = client.services().load(path).get()
-        }catch (e : Exception){
+        } catch (e: Exception) {
             logger.info("You potentially  misspeled the path: $path")
             logger.info("$e")
         }
 
         return service
     }
-}
 
+    fun loadDeployment(path: String): Deployment? {
+        val deployment = loadGenericRessource(path,{x: String-> client.apps().deployments().load(x).get()})
+        return deployment
+    }
+
+    fun <T> loadGenericRessource(path: String, f: (String) -> T): T?{
+        var service: T? = null
+
+        try {
+            service = f(path)
+        } catch (e: Exception) {
+            logger.info("You potentially  misspeled the path: $path")
+            logger.info("$e")
+        }
+
+        return service
+    }
+
+    }
+}
-- 
GitLab