From 961176342edd5bc5ca60cc54981516dc9019ff40 Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Sun, 21 Mar 2021 18:56:21 +0100 Subject: [PATCH] Add comments --- .../k8s/K8sCustomResourceWrapper.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sCustomResourceWrapper.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sCustomResourceWrapper.kt index a20018dd4..8d5ed111a 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sCustomResourceWrapper.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sCustomResourceWrapper.kt @@ -4,11 +4,26 @@ import io.fabric8.kubernetes.client.CustomResource import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext -class K8sCustomResourceWrapper(private val map : Map<String,String>) : CustomResource() { +/** + * Fabric8 handles custom resources as plain HashMaps. These need to be handled differently than normal + * Kubernetes resources. The K8sCustomResourceWrapper class provides a wrapper to deploy and delete + * custom resources in a uniform way. + * + * @property map custom resource as plain hashmap + * @constructor Create empty K8s custom resource wrapper + */ + class K8sCustomResourceWrapper(private val map : Map<String,String>) : CustomResource() { + /** + * Deploy a custom resource + * + * @param client a namespaced Kubernetes client which are used to deploy the CR object. + */ fun deploy(client : NamespacedKubernetesClient){ val kind = this.map["kind"] + // Search the CustomResourceDefinition to which the CR Object belongs. + // This should be exactly one if the CRD is registered for Kubernetes, zero otherwise. val crds = client.apiextensions().v1beta1().customResourceDefinitions().list() crds.items .filter { crd -> crd.toString().contains("kind=$kind") } @@ -18,6 +33,11 @@ class K8sCustomResourceWrapper(private val map : Map<String,String>) : CustomRes } } + /** + * Delete a custom resource + * + * @param client a namespaced Kubernetes client which are used to delete the CR object. + */ fun delete(client : NamespacedKubernetesClient){ val kind = this.map["kind"] val metadata = this.map["metadata"] as HashMap<String,String> -- GitLab