diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt index 800a43d0b6c7fa004f45dd20e66b94a972342b9e..f539ce0231dfaf6d1d6ef30bd864cd32a3ea2cfc 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt @@ -5,9 +5,8 @@ import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.NamespacedKubernetesClient import mu.KotlinLogging -import theodolite.k8s.K8sResourceLoaderFromString +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromString import theodolite.util.YamlParserFromString -import kotlin.math.log private val logger = KotlinLogging.logger {} diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt index 34a4bb86e91dcb60a2d092e0ddf24765ec23ea06..c6ae3026d81c7a4ec57af26e6c35aeaed931d94e 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.client.DefaultKubernetesClient import mu.KotlinLogging -import theodolite.k8s.K8sResourceLoader +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile import theodolite.util.DeploymentFailedException import theodolite.util.YamlParserFromFile import java.io.File @@ -17,7 +17,7 @@ class FileSystemResourceSet: ResourceSet { lateinit var path: String lateinit var files: List<String> private val parser = YamlParserFromFile() - private val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace("default")) // TODO(set namespace correctly) + private val loader = K8sResourceLoaderFromFile(DefaultKubernetesClient().inNamespace("default")) // TODO(set namespace correctly) override fun getResourceSet(): List<Pair<String, KubernetesResource>> { logger.info { "Get fileSystem resource set $path" } diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index 48d77429aa6320c80fa7ae6abd762d8e3a7186bb..049de2a9036a4012f57cad9245160c5056e07e2a 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -5,7 +5,7 @@ import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.quarkus.runtime.annotations.RegisterForReflection import mu.KotlinLogging -import theodolite.k8s.K8sResourceLoader +import theodolite.k8s.resourceLoader.K8sResourceLoader import theodolite.patcher.PatcherFactory import theodolite.util.* diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt index 7ca3906a4570d79553edecbad9edfac95f71fa6a..b8cd3a30e9ac8c8811a881c88552e617cadeb0db 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/ResourceSets.kt @@ -4,11 +4,8 @@ import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.annotation.JsonDeserialize import io.fabric8.kubernetes.api.model.KubernetesResource -import io.fabric8.kubernetes.client.DefaultKubernetesClient -import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.quarkus.runtime.annotations.RegisterForReflection import mu.KotlinLogging -import theodolite.k8s.K8sResourceLoaderFromString import theodolite.util.DeploymentFailedException private val logger = KotlinLogging.logger {} diff --git a/theodolite/src/main/kotlin/theodolite/k8s/AbstractK8sLoader.kt b/theodolite/src/main/kotlin/theodolite/k8s/AbstractK8sLoader.kt deleted file mode 100644 index ab4bc25d5e2010a2921f3d072cc748a59f128c63..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/k8s/AbstractK8sLoader.kt +++ /dev/null @@ -1,4 +0,0 @@ -package theodolite.k8s - -abstract class AbstractK8sLoader { -} \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt b/theodolite/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt deleted file mode 100644 index 1a4d0514a6702d1add66744155435866db490127..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt +++ /dev/null @@ -1,153 +0,0 @@ -package theodolite.k8s - -import io.fabric8.kubernetes.api.model.ConfigMap -import io.fabric8.kubernetes.api.model.KubernetesResource -import io.fabric8.kubernetes.api.model.Service -import io.fabric8.kubernetes.api.model.apps.Deployment -import io.fabric8.kubernetes.client.NamespacedKubernetesClient -import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext -import mu.KotlinLogging -import theodolite.util.YamlParserFromFile - -private val logger = KotlinLogging.logger {} - -/** - * Used to load different Kubernetes resources. - * Supports: Deployments, Services, ConfigMaps, and CustomResources. - * @param client KubernetesClient used to deploy or remove. - */ -class K8sResourceLoader(private val client: NamespacedKubernetesClient) { - - /** - * Parses a Service from a service yaml - * @param path of the yaml file - * @return Service from fabric8 - */ - private fun loadService(path: String): Service { - return loadGenericResource(path) { x: String -> client.services().load(x).get() } - } - - - /** - * Parses a CustomResource from a yaml - * @param path of the yaml file - * @param context specific crd context for this custom resource - * @return CustomResourceWrapper from fabric8 - */ - private fun loadCustomResourceWrapper(path: String, context: CustomResourceDefinitionContext): CustomResourceWrapper { - return loadGenericResource(path) { - CustomResourceWrapper( - YamlParserFromFile().parse( - path, - HashMap<String, String>()::class.java - )!!, - context - ) - } - } - - private fun loadServiceMonitor(path: String): CustomResourceWrapper { - val context = K8sContextFactory().create( - api = "v1", - scope = "Namespaced", - group = "monitoring.coreos.com", - plural = "servicemonitors" - ) - return loadCustomResourceWrapper(path, context) - } - - private fun loadExecution(path: String): KubernetesResource { - val context = K8sContextFactory().create( - api = "v1", - scope = "Namespaced", - group = "theodolite.com", - plural = "executions" - ) - return loadCustomResourceWrapper(path, context) - } - - private fun loadBenchmark(path: String): KubernetesResource { - val context = K8sContextFactory().create( - api = "v1", - scope = "Namespaced", - group = "theodolite.com", - plural = "benchmarks" - ) - return loadCustomResourceWrapper(path, context) - } - - - /** - * Parses a Deployment from a Deployment yaml - * @param path of the yaml file - * @return Deployment from fabric8 - */ - private fun loadDeployment(path: String): Deployment { - return loadGenericResource(path) { x: String -> client.apps().deployments().load(x).get() } - } - - /** - * Parses a ConfigMap from a ConfigMap yaml - * @param path of the yaml file - * @return ConfigMap from fabric8 - */ - private fun loadConfigmap(path: String): ConfigMap { - return loadGenericResource(path) { x: String -> client.configMaps().load(x).get() } - } - - /** - * Parses a StatefulSet from a StatefulSet yaml - * @param path of the yaml file - * @return StatefulSet from fabric8 - */ - private fun loadStatefulSet(path: String): KubernetesResource { - return loadGenericResource(path) { x: String -> client.apps().statefulSets().load(x).get() } - - } - - /** - * Generic helper function to load a resource. - * @param path of the resource - * @param f function that is applied to the resource. - * @throws IllegalArgumentException If the resource could not be loaded. - */ - private fun <T> loadGenericResource(path: String, f: (String) -> T): T { - var resource: T? = null - - try { - resource = f(path) - } catch (e: Exception) { - logger.warn { "You potentially misspelled the path: $path" } - logger.warn { e } - } - - if (resource == null) { - throw IllegalArgumentException("The Resource at path: $path could not be loaded") - } - return resource - } - - /** - * Factory function used to load different k8s resources from a path. - * Supported kinds are: Deployments, Services, ServiceMonitors, ConfigMaps and CustomResources. - * Uses CustomResource as default if Kind is not supported. - * @param kind of the resource. CustomResource as default. - * @param path of the resource to be loaded. - * @throws Exception if the resource could not be loaded. - */ - fun loadK8sResource(kind: String, path: String): KubernetesResource { - return when (kind) { - "Deployment" -> loadDeployment(path) - "Service" -> loadService(path) - "ServiceMonitor" -> loadServiceMonitor(path) - "ConfigMap" -> loadConfigmap(path) - "StatefulSet" -> loadStatefulSet(path) - "Execution" -> loadExecution(path) - "Benchmark" -> loadBenchmark(path) - else -> { - logger.error { "Error during loading of unspecified resource Kind" } - throw java.lang.IllegalArgumentException("error while loading resource with kind: $kind") - } - } - } -} diff --git a/theodolite/src/main/kotlin/theodolite/k8s/K8sResourceLoaderFromString.kt b/theodolite/src/main/kotlin/theodolite/k8s/K8sResourceLoaderFromString.kt deleted file mode 100644 index 9ff90ad4b00e92ba872ebaaca24d357a44195703..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/k8s/K8sResourceLoaderFromString.kt +++ /dev/null @@ -1,91 +0,0 @@ -package theodolite.k8s - -import io.fabric8.kubernetes.api.model.ConfigMap -import io.fabric8.kubernetes.api.model.KubernetesResource -import io.fabric8.kubernetes.api.model.Service -import io.fabric8.kubernetes.api.model.apps.Deployment -import io.fabric8.kubernetes.client.NamespacedKubernetesClient -import io.fabric8.kubernetes.client.utils.Serialization -import mu.KotlinLogging -import theodolite.util.YamlParserFromString -import java.io.ByteArrayInputStream -private val logger = KotlinLogging.logger {} - - - -class K8sResourceLoaderFromString(private val client: NamespacedKubernetesClient) { - - @OptIn(ExperimentalStdlibApi::class) - fun loadK8sResource(kind: String, resourceString: String): KubernetesResource { - - return when (kind) { - "Deployment" -> loadDeployment(resourceString) - "Service" -> loadService(resourceString) - //"ServiceMonitor" -> loadServiceMonitor(resourceString) // TODO(Add support for custom resources) - "ConfigMap" -> loadConfigmap(resourceString) - "StatefulSet" -> loadStatefulSet(resourceString) - //"Execution" -> loadExecution(resourceString) - //"Benchmark" -> loadBenchmark(resourceString) - else -> { - logger.error { "Error during loading of unspecified resource Kind" } - throw java.lang.IllegalArgumentException("error while loading resource with kind: $kind") - } - } - } - - /** - * Generic helper function to load a resource. - * @param path of the resource - * @param f function that is applied to the resource. - * @throws IllegalArgumentException If the resource could not be loaded. - */ - @OptIn(ExperimentalStdlibApi::class) - private fun <T> loadGenericResource(resourceString: String, f: (ByteArrayInputStream) -> T): T { - val stream = ByteArrayInputStream(resourceString.encodeToByteArray()) - var resource: T? = null - - try { - resource = f(stream) - } catch (e: Exception) { - logger.warn { "You potentially misspelled the path: ....1" } - logger.warn { e } - } - - if (resource == null) { - throw IllegalArgumentException("The Resource: ....1 could not be loaded") - } - return resource - } - - - @OptIn(ExperimentalStdlibApi::class) - private fun loadService(resourceStream: String): KubernetesResource { - - //logger.info { resourceStream } - - val stream = ByteArrayInputStream(resourceStream.encodeToByteArray()) - //val test = Serialization.unmarshal<Service>(stream, Service::class.java) - //logger.info { test } - // return test - logger.info { "Test" } - //val parser = YamlParserFromString() - //val resoureceAsMap = parser.parse(resourceStream, HashMap<String, String>()::class.java) - //val loadedSvc: Service = client.services().load(stream).get() - //logger.info { "loadedSvc" } - //return loadedSvc - //logger.info { "try to load service" } - return loadGenericResource(resourceStream) { x: ByteArrayInputStream -> client.services().load(x).get() } - } - - private fun loadDeployment(path: String): Deployment { - return loadGenericResource(path) { x: ByteArrayInputStream -> client.apps().deployments().load(x).get() } - } - - private fun loadConfigmap(path: String): ConfigMap { - return loadGenericResource(path) { x: ByteArrayInputStream -> client.configMaps().load(x).get() } - } - - private fun loadStatefulSet(path: String): KubernetesResource { - return loadGenericResource(path) { x: ByteArrayInputStream -> client.apps().statefulSets().load(x).get() } - } -} \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sAbstractLoader.kt b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sAbstractLoader.kt new file mode 100644 index 0000000000000000000000000000000000000000..09cee6953b51a97a330819643b21a6332492ecdf --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sAbstractLoader.kt @@ -0,0 +1,77 @@ +package theodolite.k8s.resourceLoader + +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext +import mu.KotlinLogging +import theodolite.k8s.K8sContextFactory + +private val logger = KotlinLogging.logger {} + +abstract class AbstractK8sLoader: K8sResourceLoader { + + abstract fun loadCustomResourceWrapper(path: String, context: CustomResourceDefinitionContext): KubernetesResource + + fun loadK8sResource(kind: String, resourceString: String): KubernetesResource { + return when (kind) { + "Deployment" -> loadDeployment(resourceString) + "Service" -> loadService(resourceString) + "ServiceMonitor" -> loadServiceMonitor(resourceString) + "ConfigMap" -> loadConfigmap(resourceString) + "StatefulSet" -> loadStatefulSet(resourceString) + "Execution" -> loadExecution(resourceString) + "Benchmark" -> loadBenchmark(resourceString) + else -> { + logger.error { "Error during loading of unspecified resource Kind" } + throw java.lang.IllegalArgumentException("error while loading resource with kind: $kind") + } + } + } + + fun <T> loadGenericResource(resourceString: String, f: (String) -> T): T { + var resource: T? = null + + try { + resource = f(resourceString) + } catch (e: Exception) { + logger.warn { "You potentially misspelled the path: ....1" } + logger.warn { e } + } + + if (resource == null) { + throw IllegalArgumentException("The Resource: ....1 could not be loaded") + } + return resource + } + + + + override fun loadServiceMonitor(path: String): KubernetesResource { + val context = K8sContextFactory().create( + api = "v1", + scope = "Namespaced", + group = "monitoring.coreos.com", + plural = "servicemonitors" + ) + return loadCustomResourceWrapper(path, context) + } + + override fun loadExecution(path: String): KubernetesResource { + val context = K8sContextFactory().create( + api = "v1", + scope = "Namespaced", + group = "theodolite.com", + plural = "executions" + ) + return loadCustomResourceWrapper(path, context) + } + + override fun loadBenchmark(path: String): KubernetesResource { + val context = K8sContextFactory().create( + api = "v1", + scope = "Namespaced", + group = "theodolite.com", + plural = "benchmarks" + ) + return loadCustomResourceWrapper(path, context) + } +} \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoader.kt b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoader.kt new file mode 100644 index 0000000000000000000000000000000000000000..5f8643717913cb2e9e9598f8861f522b48d2f3ee --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoader.kt @@ -0,0 +1,13 @@ +package theodolite.k8s.resourceLoader + +import io.fabric8.kubernetes.api.model.KubernetesResource + +interface K8sResourceLoader { + fun loadDeployment(resource: String): KubernetesResource + fun loadService(resource: String): KubernetesResource + fun loadStatefulSet(resource: String): KubernetesResource + fun loadExecution(resource: String): KubernetesResource + fun loadBenchmark(resource: String): KubernetesResource + fun loadConfigmap(resource: String): KubernetesResource + fun loadServiceMonitor(resource: String): KubernetesResource +} \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromFile.kt b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromFile.kt new file mode 100644 index 0000000000000000000000000000000000000000..a970ea4ef04dcc1ba9b77d96ee71c627389e0e11 --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromFile.kt @@ -0,0 +1,75 @@ +package theodolite.k8s.resourceLoader + +import io.fabric8.kubernetes.api.model.ConfigMap +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.Service +import io.fabric8.kubernetes.api.model.apps.Deployment +import io.fabric8.kubernetes.client.NamespacedKubernetesClient +import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext +import theodolite.k8s.CustomResourceWrapper +import theodolite.util.YamlParserFromFile + +/** + * Used to load different Kubernetes resources. + * Supports: Deployments, Services, ConfigMaps, and CustomResources. + * @param client KubernetesClient used to deploy or remove. + */ +class K8sResourceLoaderFromFile(private val client: NamespacedKubernetesClient): AbstractK8sLoader(), + K8sResourceLoader { + + /** + * Parses a Service from a service yaml + * @param path of the yaml file + * @return Service from fabric8 + */ + override fun loadService(path: String): Service { + return loadGenericResource(path) { x: String -> client.services().load(x).get() } + } + + + /** + * Parses a CustomResource from a yaml + * @param path of the yaml file + * @param context specific crd context for this custom resource + * @return CustomResourceWrapper from fabric8 + */ + override fun loadCustomResourceWrapper(path: String, context: CustomResourceDefinitionContext): CustomResourceWrapper { + return loadGenericResource(path) { + CustomResourceWrapper( + YamlParserFromFile().parse( + path, + HashMap<String, String>()::class.java + )!!, + context + ) + } + } + + /** + * Parses a Deployment from a Deployment yaml + * @param path of the yaml file + * @return Deployment from fabric8 + */ + override fun loadDeployment(path: String): Deployment { + return loadGenericResource(path) { x: String -> client.apps().deployments().load(x).get() } + } + + /** + * Parses a ConfigMap from a ConfigMap yaml + * @param path of the yaml file + * @return ConfigMap from fabric8 + */ + override fun loadConfigmap(path: String): ConfigMap { + return loadGenericResource(path) { x: String -> client.configMaps().load(x).get() } + } + + /** + * Parses a StatefulSet from a StatefulSet yaml + * @param path of the yaml file + * @return StatefulSet from fabric8 + */ + override fun loadStatefulSet(path: String): KubernetesResource { + return loadGenericResource(path) { x: String -> client.apps().statefulSets().load(x).get() } + + } +} diff --git a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromString.kt b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromString.kt new file mode 100644 index 0000000000000000000000000000000000000000..9ddf22119869ec56f093d264c4afb5347de851de --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromString.kt @@ -0,0 +1,60 @@ +package theodolite.k8s.resourceLoader + +import io.fabric8.kubernetes.api.model.ConfigMap +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.apps.Deployment +import io.fabric8.kubernetes.client.NamespacedKubernetesClient +import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext +import theodolite.k8s.CustomResourceWrapper +import theodolite.util.YamlParserFromString +import java.io.ByteArrayInputStream + +class K8sResourceLoaderFromString(private val client: NamespacedKubernetesClient): AbstractK8sLoader(), + K8sResourceLoader { + + @OptIn(ExperimentalStdlibApi::class) + override fun loadService(resourceStream: String): KubernetesResource { + return loadGenericResource(resourceStream) { x: String -> + val stream = ByteArrayInputStream(x.encodeToByteArray()) + client.services().load(stream).get() } + } + + @OptIn(ExperimentalStdlibApi::class) + override fun loadDeployment(path: String): Deployment { + return loadGenericResource(path) { x: String -> + val stream = ByteArrayInputStream(x.encodeToByteArray()) + client.apps().deployments().load(stream).get() } + } + + @OptIn(ExperimentalStdlibApi::class) + override fun loadConfigmap(path: String): ConfigMap { + return loadGenericResource(path) { x: String -> + val stream = ByteArrayInputStream(x.encodeToByteArray()) + client.configMaps().load(stream).get() } + } + + @OptIn(ExperimentalStdlibApi::class) + override fun loadStatefulSet(path: String): KubernetesResource { + return loadGenericResource(path) { x: String -> + val stream = ByteArrayInputStream(x.encodeToByteArray()) + client.apps().statefulSets().load(stream).get() } + } + + /** + * Parses a CustomResource from a yaml + * @param path of the yaml file + * @param context specific crd context for this custom resource + * @return CustomResourceWrapper from fabric8 + */ + override fun loadCustomResourceWrapper(path: String, context: CustomResourceDefinitionContext): CustomResourceWrapper { + return loadGenericResource(path) { + CustomResourceWrapper( + YamlParserFromString().parse( + path, + HashMap<String, String>()::class.java + )!!, + context + ) + } + } +} \ No newline at end of file diff --git a/theodolite/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt b/theodolite/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt index e88192dd7fe4393494a4fb76bd74d1123bd75f1d..46758583172c3fcd6417e17ff5bab85f8659734b 100644 --- a/theodolite/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt +++ b/theodolite/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt @@ -5,7 +5,7 @@ import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.quarkus.test.junit.QuarkusTest import io.smallrye.common.constraint.Assert.assertTrue import org.junit.jupiter.api.Test -import theodolite.k8s.K8sResourceLoader +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile import theodolite.patcher.PatcherFactory import theodolite.util.PatcherDefinition @@ -22,7 +22,7 @@ import theodolite.util.PatcherDefinition @QuarkusTest class ResourceLimitPatcherTest { val testPath = "./src/test/resources/" - val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace("")) + val loader = K8sResourceLoaderFromFile(DefaultKubernetesClient().inNamespace("")) val patcherFactory = PatcherFactory() fun applyTest(fileName: String) { diff --git a/theodolite/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt b/theodolite/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt index 2af6c632567bf47e150a74808ab009bd0bc0598a..8794d4dc2d67b8af78f4fa409c727f882922d0b8 100644 --- a/theodolite/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt +++ b/theodolite/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt @@ -5,7 +5,7 @@ import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.quarkus.test.junit.QuarkusTest import io.smallrye.common.constraint.Assert.assertTrue import org.junit.jupiter.api.Test -import theodolite.k8s.K8sResourceLoader +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile import theodolite.patcher.PatcherFactory import theodolite.util.PatcherDefinition @@ -22,7 +22,7 @@ import theodolite.util.PatcherDefinition @QuarkusTest class ResourceRequestPatcherTest { val testPath = "./src/test/resources/" - val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace("")) + val loader = K8sResourceLoaderFromFile(DefaultKubernetesClient().inNamespace("")) val patcherFactory = PatcherFactory() fun applyTest(fileName: String) { diff --git a/theodolite/src/test/kotlin/theodolite/execution/operator/ExecutionEventHandlerTest.kt b/theodolite/src/test/kotlin/theodolite/execution/operator/ExecutionEventHandlerTest.kt index bbbb3092cd54a8f3313bb923be3682be50801f39..a026a349e803a523c5b4725143a5304e3f1b068e 100644 --- a/theodolite/src/test/kotlin/theodolite/execution/operator/ExecutionEventHandlerTest.kt +++ b/theodolite/src/test/kotlin/theodolite/execution/operator/ExecutionEventHandlerTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import theodolite.k8s.K8sManager -import theodolite.k8s.K8sResourceLoader +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile import theodolite.model.crd.States import java.lang.Thread.sleep @@ -42,10 +42,10 @@ class ExecutionEventHandlerTest { this.factory = operator.getExecutionEventHandler(this.controller,server.client) this.stateHandler = TheodoliteOperator().getExecutionStateHandler(client = server.client) - this.executionVersion1 = K8sResourceLoader(server.client) + this.executionVersion1 = K8sResourceLoaderFromFile(server.client) .loadK8sResource("Execution", testResourcePath + "test-execution.yaml") - this.executionVersion2 = K8sResourceLoader(server.client) + this.executionVersion2 = K8sResourceLoaderFromFile(server.client) .loadK8sResource("Execution", testResourcePath + "test-execution-update.yaml") this.stateHandler = operator.getExecutionStateHandler(server.client) diff --git a/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt b/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt index de74cf9ac87a8aca7db133a04ef3809c5e5087c2..00393dabb1802ecb477c9824352978f1fb98e7e7 100644 --- a/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt +++ b/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt @@ -8,7 +8,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import theodolite.k8s.K8sManager -import theodolite.k8s.K8sResourceLoader +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile import theodolite.model.crd.States import java.time.Duration @@ -19,7 +19,7 @@ class StateHandlerTest { @BeforeEach fun setUp() { server.before() - val executionResource = K8sResourceLoader(server.client) + val executionResource = K8sResourceLoaderFromFile(server.client) .loadK8sResource("Execution", testResourcePath + "test-execution.yaml") K8sManager(server.client).deploy(executionResource) diff --git a/theodolite/src/test/kotlin/theodolite/execution/operator/testTest.kt b/theodolite/src/test/kotlin/theodolite/execution/operator/testTest.kt index 9fa32f79fd92eeeb775b6324070b0453a7034be3..6bd4ced35014e20d143a1ba143a677dd0be7c7ce 100644 --- a/theodolite/src/test/kotlin/theodolite/execution/operator/testTest.kt +++ b/theodolite/src/test/kotlin/theodolite/execution/operator/testTest.kt @@ -1,4 +1,37 @@ package theodolite.execution.operator +import io.fabric8.kubernetes.client.DefaultKubernetesClient +import io.quarkus.test.junit.QuarkusTest +import mu.KotlinLogging +import org.junit.jupiter.api.Test + +private val logger = KotlinLogging.logger {} + + +@QuarkusTest class testTest { + + + @Test + fun test(){ + val operator = TheodoliteOperator() + val client = DefaultKubernetesClient().inNamespace("default") + val benchmarkClient = operator.getBenchmarkClient(client = client) + val benchmarks = benchmarkClient + .list() + .items + + val r = benchmarks.map{ + it.spec.loadKubernetesResources(it.spec.loadGenResourceSets) + } + + + + r.forEach { + it?.forEach{ + logger.info { it } + } + } + + } } \ No newline at end of file diff --git a/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt b/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt index dc2bf016994d79b1021bebdc751102e291d60682..7c69618de03f730f5b6f1cb83c5df544e2cd120c 100644 --- a/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt +++ b/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt @@ -15,6 +15,7 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile private val logger = KotlinLogging.logger {} @@ -125,7 +126,7 @@ class K8sManagerTest { @DisplayName("Test handling of custom resources") fun handleCustomResourcesTest() { val manager = K8sManager(server.client) - val servicemonitor = K8sResourceLoader(server.client) + val servicemonitor = K8sResourceLoaderFromFile(server.client) .loadK8sResource("ServiceMonitor", testResourcePath + "test-service-monitor.yaml") val serviceMonitorContext = K8sContextFactory().create( diff --git a/theodolite/src/test/kotlin/theodolite/k8s/K8sResourceLoaderTest.kt b/theodolite/src/test/kotlin/theodolite/k8s/K8sResourceLoaderTest.kt index 7c2aa50007274ff9b4d49f1c0cc05ae45a37d323..4a41dac8b27b9d4ddcfb9915f759b14ea4eaba4a 100644 --- a/theodolite/src/test/kotlin/theodolite/k8s/K8sResourceLoaderTest.kt +++ b/theodolite/src/test/kotlin/theodolite/k8s/K8sResourceLoaderTest.kt @@ -12,6 +12,7 @@ import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile @QuarkusTest class K8sResourceLoaderTest { @@ -31,7 +32,7 @@ class K8sResourceLoaderTest { @Test @DisplayName("Test loading of Deployments") fun loadDeploymentTest() { - val loader = K8sResourceLoader(server.client) + val loader = K8sResourceLoaderFromFile(server.client) val resource = loader.loadK8sResource("Deployment", testResourcePath + "test-deployment.yaml") assertTrue(resource is Deployment) @@ -41,7 +42,7 @@ class K8sResourceLoaderTest { @Test @DisplayName("Test loading of StatefulSet") fun loadStatefulSetTest() { - val loader = K8sResourceLoader(server.client) + val loader = K8sResourceLoaderFromFile(server.client) val resource = loader.loadK8sResource("StatefulSet", testResourcePath + "test-statefulset.yaml") assertTrue(resource is StatefulSet) @@ -51,7 +52,7 @@ class K8sResourceLoaderTest { @Test @DisplayName("Test loading of Service") fun loadServiceTest() { - val loader = K8sResourceLoader(server.client) + val loader = K8sResourceLoaderFromFile(server.client) val resource = loader.loadK8sResource("Service", testResourcePath + "test-service.yaml") assertTrue(resource is Service) @@ -61,7 +62,7 @@ class K8sResourceLoaderTest { @Test @DisplayName("Test loading of ConfigMap") fun loadConfigMapTest() { - val loader = K8sResourceLoader(server.client) + val loader = K8sResourceLoaderFromFile(server.client) val resource = loader.loadK8sResource("ConfigMap", testResourcePath + "test-configmap.yaml") assertTrue(resource is ConfigMap) @@ -71,7 +72,7 @@ class K8sResourceLoaderTest { @Test @DisplayName("Test loading of ServiceMonitors") fun loadServiceMonitorTest() { - val loader = K8sResourceLoader(server.client) + val loader = K8sResourceLoaderFromFile(server.client) val resource = loader.loadK8sResource("ServiceMonitor", testResourcePath + "test-service-monitor.yaml") assertTrue(resource is CustomResourceWrapper) @@ -84,7 +85,7 @@ class K8sResourceLoaderTest { @Test @DisplayName("Test loading of Executions") fun loadExecutionTest() { - val loader = K8sResourceLoader(server.client) + val loader = K8sResourceLoaderFromFile(server.client) val resource = loader.loadK8sResource("Execution", testResourcePath + "test-execution.yaml") assertTrue(resource is CustomResourceWrapper) @@ -97,7 +98,7 @@ class K8sResourceLoaderTest { @Test @DisplayName("Test loading of Benchmarks") fun loadBenchmarkTest() { - val loader = K8sResourceLoader(server.client) + val loader = K8sResourceLoaderFromFile(server.client) val resource = loader.loadK8sResource("Benchmark", testResourcePath + "test-benchmark.yaml") assertTrue(resource is CustomResourceWrapper)