diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sCustomResourceWrapper.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sCustomResourceWrapper.kt index a20018dd4ec050a6a20adde3f0e4d5b595a61585..8d5ed111ab1091440f5abf44c5b127464b40a461 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>