Skip to content
Snippets Groups Projects
Commit f57244e0 authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

Add first running way to create a CR object

parent 45af762b
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!101Add Service Monitor,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
...@@ -12,7 +12,9 @@ import io.fabric8.kubernetes.client.CustomResource ...@@ -12,7 +12,9 @@ import io.fabric8.kubernetes.client.CustomResource
import io.fabric8.kubernetes.api.model.HasMetadata import io.fabric8.kubernetes.api.model.HasMetadata
import io.fabric8.kubernetes.internal.KubernetesDeserializer import io.fabric8.kubernetes.internal.KubernetesDeserializer
import theodolite.util.YamlParser
import java.io.File import java.io.File
import java.io.IOException
import javax.json.Json import javax.json.Json
...@@ -81,4 +83,22 @@ class CustomRessourceTest { ...@@ -81,4 +83,22 @@ class CustomRessourceTest {
println(crd) println(crd)
} }
@Test
fun testTypelessAPI() {
try {
DefaultKubernetesClient().use { client ->
val svmAsMap = YamlParser().parse(path + "uc1-service-monitor.yaml", HashMap<String, String>()::class.java)
val kind = svmAsMap?.get("kind")
val crds = client.apiextensions().v1beta1().customResourceDefinitions().list()
crds.items
.filter { crd -> crd.toString().contains("kind=$kind") } // the filtered list should contain exactly 1 element, iff the CRD is known. TODO("Check if there is a case in which the list contains more than 1 element")
.map { crd -> CustomResourceDefinitionContext.fromCrd(crd)}
.forEach {context -> client.customResource(context).createOrReplace("default", svmAsMap as Map<String, Any>?)}
}
} catch (e: IOException) {
e.printStackTrace()
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment