From becfb5e94669085e9185de3c670ef39fe4f218b0 Mon Sep 17 00:00:00 2001
From: lorenz <stu203404@mail.uni-kiel.de>
Date: Thu, 28 Jan 2021 19:54:06 +0100
Subject: [PATCH] Refactor

---
 .../main/kotlin/theodolite/ServiceManager.kt  |  2 +-
 .../src/main/kotlin/theodolite/YamlLoader.kt  | 24 +++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/ServiceManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/ServiceManager.kt
index d24877bfe..1e8f627f2 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/ServiceManager.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/ServiceManager.kt
@@ -4,7 +4,7 @@ import io.fabric8.kubernetes.api.model.Service
 import io.fabric8.kubernetes.client.NamespacedKubernetesClient
 
 class ServiceManager(client: NamespacedKubernetesClient) {
-    lateinit var client: NamespacedKubernetesClient
+    var client: NamespacedKubernetesClient
 
     init {
         this.client = client
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt b/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt
index 2c338f664..1a7e36dab 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/YamlLoader.kt
@@ -9,29 +9,49 @@ import mu.KotlinLogging
 private val logger = KotlinLogging.logger {}
 
 class YamlLoader(client: NamespacedKubernetesClient) {
-    lateinit var client: NamespacedKubernetesClient
+    var client: NamespacedKubernetesClient
 
     init {
         this.client = client
     }
 
+    /**
+     * Parses a Service from a servive yaml
+     * @param path of the yaml file
+     * @return service from fabric8
+     */
     fun loadService(path: String): Service? {
 
         val service = loadGenericRessource(path, { x: String -> client.services().load(x).get() })
         return service
     }
 
+    /**
+     * Parses a Deployment from a Deployment yaml
+     * @param path of the yaml file
+     * @return Deployment from fabric8
+     */
     fun loadDeployment(path: String): Deployment? {
         val deployment = loadGenericRessource(path, { x: String -> client.apps().deployments().load(x).get() })
         return deployment
     }
 
+    /**
+     * Parses a ConfigMap from a ConfigMap yaml
+     * @param path of the yaml file
+     * @return ConfigMap from fabric8
+     */
     fun loadConfigmap(path: String): ConfigMap? {
         val configMap = loadGenericRessource(path, { x: String -> client.configMaps().load(x).get() })
         return configMap
     }
 
-    fun <T> loadGenericRessource(path: String, f: (String) -> T): T? {
+    /**
+     * Generic helper function to load a resource.
+     * @param path of the resource
+     * @param f fuction that shall be applied to the resource.
+     */
+    private fun <T> loadGenericRessource(path: String, f: (String) -> T): T? {
         var resource: T? = null
 
         try {
-- 
GitLab