diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt index 864ec574899cb07a34741443711fe983a92c47ab..2192f43a088c5cb79ba514cde6225a5efef4a181 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/ConfigMapResourceSet.kt @@ -6,9 +6,7 @@ import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.client.KubernetesClientException import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.quarkus.runtime.annotations.RegisterForReflection -import theodolite.k8s.resourceLoader.K8sResourceLoaderFromString import theodolite.util.DeploymentFailedException -import theodolite.util.YamlParserFromString import java.lang.IllegalArgumentException @RegisterForReflection @@ -18,7 +16,6 @@ class ConfigMapResourceSet : ResourceSet, KubernetesResource { lateinit var files: List<String> // load all files, iff files is not set override fun getResourceSet(client: NamespacedKubernetesClient): Collection<Pair<String, HasMetadata>> { - val loader = K8sResourceLoaderFromString(client) var resources: Map<String, String> try { @@ -44,15 +41,8 @@ class ConfigMapResourceSet : ResourceSet, KubernetesResource { resources .map { Pair( - getKind(resourceYaml = it.value), - it - ) - } - .map { - Pair( - it.second.key, // filename - client.resource(it.second.value).get() - //loader.loadK8sResource(kind = it.first, resourceString = it.second.value) // K8s resource + it.key, // filename + client.resource(it.value).get() ) } } catch (e: IllegalArgumentException) { @@ -61,11 +51,4 @@ class ConfigMapResourceSet : ResourceSet, KubernetesResource { } - private fun getKind(resourceYaml: String): String { - val parser = YamlParserFromString() - val resourceAsMap = parser.parse(resourceYaml, HashMap<String, String>()::class.java) - - return resourceAsMap?.get("kind") - ?: throw DeploymentFailedException("Could not find 'kind' field of Kubernetes resource: ${resourceAsMap?.get("name")}") - } } \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt index 9b3997fbb76adaf730c770406fa35c62d48eb24a..cfd7197193ba98dd10500f8612282cb170749e32 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/FileSystemResourceSet.kt @@ -43,7 +43,6 @@ class FileSystemResourceSet: ResourceSet, KubernetesResource { private fun loadSingleResource(resource: Path, client: NamespacedKubernetesClient): Pair<String, HasMetadata> { return try { - //val k8sResource = client.load(FileInputStream(resource.toFile())).get()[0] val stream = FileInputStream(resource.toFile()) val text = BufferedReader( InputStreamReader(stream, StandardCharsets.UTF_8) diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index 5aad784ea17c24470b62a8b86fa5a5b09822ee52..6857b9bf8918593dbe5085f40eb28fd8bd809d85 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -8,7 +8,6 @@ import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.quarkus.runtime.annotations.RegisterForReflection import mu.KotlinLogging import theodolite.k8s.K8sManager -import theodolite.k8s.resourceLoader.K8sResourceLoader import theodolite.patcher.PatcherFactory import theodolite.util.* @@ -54,22 +53,26 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { * It first loads them via the [YamlParserFromFile] to check for their concrete type and afterwards initializes them using * the [K8sResourceLoader] */ + @Deprecated("Use `loadResourceSet` from `ResourceSets`") fun loadKubernetesResources(resourceSet: List<ResourceSets>): Collection<Pair<String, HasMetadata>> { + return loadResources(resourceSet) + } + + private fun loadResources(resourceSet: List<ResourceSets>): Collection<Pair<String, HasMetadata>> { return resourceSet.flatMap { it.loadResourceSet(this.client) } } override fun setupInfrastructure() { this.infrastructure.beforeActions.forEach { it.exec(client = client) } val kubernetesManager = K8sManager(this.client) - loadKubernetesResources(this.infrastructure.resources) + loadResources(this.infrastructure.resources) .map { it.second } - // .forEach { client.resource(it).createOrReplace() } .forEach { kubernetesManager.deploy(it) } } override fun teardownInfrastructure() { val kubernetesManager = K8sManager(this.client) - loadKubernetesResources(this.infrastructure.resources) + loadResources(this.infrastructure.resources) .map { it.second } .forEach { kubernetesManager.remove(it) } this.infrastructure.afterActions.forEach { it.exec(client = client) } @@ -93,8 +96,8 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { ): BenchmarkDeployment { logger.info { "Using $namespace as namespace." } - val appResources = loadKubernetesResources(this.sut.resources) - val loadGenResources = loadKubernetesResources(this.loadGenerator.resources) + val appResources = loadResources(this.sut.resources) + val loadGenResources = loadResources(this.loadGenerator.resources) val patcherFactory = PatcherFactory() @@ -124,7 +127,7 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { loadGenResources = loadGenResources.map { it.second }, loadGenerationDelay = loadGenerationDelay, afterTeardownDelay = afterTeardownDelay, - kafkaConfig = if (kafkaConfig != null) hashMapOf("bootstrap.servers" to kafkaConfig.bootstrapServer) else mapOf(), + kafkaConfig = if (kafkaConfig != null) mapOf("bootstrap.servers" to kafkaConfig.bootstrapServer) else mapOf(), topics = kafkaConfig?.topics ?: listOf(), client = this.client ) diff --git a/theodolite/src/main/kotlin/theodolite/k8s/K8sManager.kt b/theodolite/src/main/kotlin/theodolite/k8s/K8sManager.kt index f897cf177e96da316c733b1c51bee37a5595d9c8..5b4880b45db76d9e68e87fda0ece5b04966439c8 100644 --- a/theodolite/src/main/kotlin/theodolite/k8s/K8sManager.kt +++ b/theodolite/src/main/kotlin/theodolite/k8s/K8sManager.kt @@ -24,20 +24,6 @@ class K8sManager(private val client: NamespacedKubernetesClient) { */ fun deploy(resource: HasMetadata) { client.resource(resource).createOrReplace() - /* - when (resource) { - is Deployment -> - this.client.apps().deployments().createOrReplace(resource) - is Service -> - this.client.services().createOrReplace(resource) - is ConfigMap -> - this.client.configMaps().createOrReplace(resource) - is StatefulSet -> - this.client.apps().statefulSets().createOrReplace(resource) - is CustomResourceWrapper -> resource.deploy(client) - else -> throw IllegalArgumentException("Unknown Kubernetes resource.") - } - */ } /** @@ -48,29 +34,19 @@ class K8sManager(private val client: NamespacedKubernetesClient) { client.resource(resource).delete() when (resource) { is Deployment -> { - //this.client.apps().deployments().delete(resource) ResourceByLabelHandler(client = client) .blockUntilPodsDeleted( matchLabels = resource.spec.selector.matchLabels ) logger.info { "Deployment '${resource.metadata.name}' deleted." } } - /* - is Service -> - this.client.services().delete(resource) - is ConfigMap -> - this.client.configMaps().delete(resource) - */ is StatefulSet -> { - //this.client.apps().statefulSets().delete(resource) ResourceByLabelHandler(client = client) .blockUntilPodsDeleted( matchLabels = resource.spec.selector.matchLabels ) logger.info { "StatefulSet '$resource.metadata.name' deleted." } } - // is CustomResourceWrapper -> resource.delete(client) - // else -> client.resource(resource).delete() } } } diff --git a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/AbstractK8sLoader.kt b/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/AbstractK8sLoader.kt deleted file mode 100644 index 285e30a70e8a4ba3eadbb9a664c99b4b001b9d4e..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/AbstractK8sLoader.kt +++ /dev/null @@ -1,85 +0,0 @@ -package theodolite.k8s.resourceLoader - -import io.fabric8.kubernetes.api.model.KubernetesResource -import mu.KotlinLogging -import theodolite.k8s.K8sContextFactory - -private val logger = KotlinLogging.logger {} - -@Deprecated("Use Kubernetes Client directly") -abstract class AbstractK8sLoader: K8sResourceLoader { - - fun loadK8sResource(kind: String, resourceString: String): KubernetesResource { - return when (kind.replaceFirst(kind[0],kind[0].uppercaseChar())) { - "Deployment" -> loadDeployment(resourceString) - "Service" -> loadService(resourceString) - "ServiceMonitor" -> loadServiceMonitor(resourceString) - "PodMonitor" -> loadPodMonitor(resourceString) - "ConfigMap" -> loadConfigmap(resourceString) - "StatefulSet" -> loadStatefulSet(resourceString) - "Execution" -> loadExecution(resourceString) - "Benchmark" -> loadBenchmark(resourceString) - else -> { - logger.error { "Error during loading of unspecified resource Kind '$kind'." } - throw IllegalArgumentException("error while loading resource with kind: $kind") - } - } - } - - fun <T : KubernetesResource> loadGenericResource(resourceString: String, f: (String) -> T): T { - var resource: T? = null - - try { - resource = f(resourceString) - } catch (e: Exception) { - logger.warn { e } - } - - if (resource == null) { - throw IllegalArgumentException("The Resource: $resourceString could not be loaded") - } - return resource - } - - - - override fun loadServiceMonitor(resource: String): KubernetesResource { - val context = K8sContextFactory().create( - api = "v1", - scope = "Namespaced", - group = "monitoring.coreos.com", - plural = "servicemonitors" - ) - return loadCustomResourceWrapper(resource, context) - } - - override fun loadPodMonitor(resource: String): KubernetesResource { - val context = K8sContextFactory().create( - api = "v1", - scope = "Namespaced", - group = "monitoring.coreos.com", - plural = "podmonitors" - ) - return loadCustomResourceWrapper(resource, context) - } - - override fun loadExecution(resource: String): KubernetesResource { - val context = K8sContextFactory().create( - api = "v1", - scope = "Namespaced", - group = "theodolite.com", - plural = "executions" - ) - return loadCustomResourceWrapper(resource, context) - } - - override fun loadBenchmark(resource: String): KubernetesResource { - val context = K8sContextFactory().create( - api = "v1", - scope = "Namespaced", - group = "theodolite.com", - plural = "benchmarks" - ) - return loadCustomResourceWrapper(resource, 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 deleted file mode 100644 index 56741330f0a133b82928ba533b1bf0021b740f89..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoader.kt +++ /dev/null @@ -1,17 +0,0 @@ -package theodolite.k8s.resourceLoader - -import io.fabric8.kubernetes.api.model.KubernetesResource -import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext - -@Deprecated("Use Kubernetes Client directly") -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 - fun loadPodMonitor(resource: String): KubernetesResource - fun loadCustomResourceWrapper(resource: String, context: CustomResourceDefinitionContext): 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 deleted file mode 100644 index df1e1e4626eb665134f1f6b0abb4a78931bc4e22..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromFile.kt +++ /dev/null @@ -1,76 +0,0 @@ -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. - */ -@Deprecated("Use Kubernetes Client directly") -class K8sResourceLoaderFromFile(private val client: NamespacedKubernetesClient): AbstractK8sLoader(), - K8sResourceLoader { - - /** - * Parses a Service from a service yaml - * @param resource of the yaml file - * @return Service from fabric8 - */ - override fun loadService(resource: String): Service { - return loadGenericResource(resource) { 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(resource: String, context: CustomResourceDefinitionContext): CustomResourceWrapper { - return loadGenericResource(resource) { - CustomResourceWrapper( - YamlParserFromFile().parse( - resource, - HashMap<String, String>()::class.java - )!!, - context - ) - } - } - - /** - * Parses a Deployment from a Deployment yaml - * @param resource of the yaml file - * @return Deployment from fabric8 - */ - override fun loadDeployment(resource: String): Deployment { - return loadGenericResource(resource) { x: String -> client.apps().deployments().load(x).get() } - } - - /** - * Parses a ConfigMap from a ConfigMap yaml - * @param resource of the yaml file - * @return ConfigMap from fabric8 - */ - override fun loadConfigmap(resource: String): ConfigMap { - return loadGenericResource(resource) { x: String -> client.configMaps().load(x).get() } - } - - /** - * Parses a StatefulSet from a StatefulSet yaml - * @param resource of the yaml file - * @return StatefulSet from fabric8 - */ - override fun loadStatefulSet(resource: String): KubernetesResource { - return loadGenericResource(resource) { 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 deleted file mode 100644 index 867aaafcb5a4dfa2fbd06189c0514620d44eb33b..0000000000000000000000000000000000000000 --- a/theodolite/src/main/kotlin/theodolite/k8s/resourceLoader/K8sResourceLoaderFromString.kt +++ /dev/null @@ -1,56 +0,0 @@ -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.api.model.apps.StatefulSet -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 -import java.io.InputStream - -@Deprecated("Use Kubernetes Client directly") -class K8sResourceLoaderFromString(private val client: NamespacedKubernetesClient): AbstractK8sLoader(), - K8sResourceLoader { - - override fun loadService(resource: String): Service { - return loadAnyResource(resource) { stream -> client.services().load(stream).get() } - } - - override fun loadDeployment(resource: String): Deployment { - return loadAnyResource(resource) { stream -> client.apps().deployments().load(stream).get() } - } - - override fun loadConfigmap(resource: String): ConfigMap { - return loadAnyResource(resource) { stream -> client.configMaps().load(stream).get() } - } - - override fun loadStatefulSet(resource: String): StatefulSet { - return loadAnyResource(resource) { stream -> client.apps().statefulSets().load(stream).get() } - } - - private fun <T : KubernetesResource> loadAnyResource(resource: String, f: (InputStream) -> T): T { - return loadGenericResource(resource) { f(ByteArrayInputStream(it.encodeToByteArray())) } - } - - /** - * Parses a CustomResource from a yaml - * @param resource of the yaml file - * @param context specific crd context for this custom resource - * @return CustomResourceWrapper from fabric8 - */ - override fun loadCustomResourceWrapper(resource: String, context: CustomResourceDefinitionContext): CustomResourceWrapper { - return loadGenericResource(resource) { - CustomResourceWrapper( - YamlParserFromString().parse( - resource, - HashMap<String, String>()::class.java - )!!, - context - ) - } - } -} \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/util/PatcherDefinition.kt b/theodolite/src/main/kotlin/theodolite/util/PatcherDefinition.kt index 6ec0cce36751ec0343d40aa49fefa44f4c7fc918..fd2ac209a52e0d516ffa9ec07e465fa076ae665a 100644 --- a/theodolite/src/main/kotlin/theodolite/util/PatcherDefinition.kt +++ b/theodolite/src/main/kotlin/theodolite/util/PatcherDefinition.kt @@ -21,5 +21,5 @@ class PatcherDefinition { lateinit var resource: String @JsonSerialize - lateinit var properties: MutableMap<String, String> + lateinit var properties: Map<String, String> } diff --git a/theodolite/src/test/kotlin/MockServerUtils.kt b/theodolite/src/test/kotlin/MockServerUtils.kt index fd4e09e766554be33a86a7182eb436aad5f8b6fe..0c8da45cd5d2dab948f9ccba1c2f4917050bb040 100644 --- a/theodolite/src/test/kotlin/MockServerUtils.kt +++ b/theodolite/src/test/kotlin/MockServerUtils.kt @@ -4,15 +4,10 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesServer fun KubernetesServer.registerResource(context: ResourceDefinitionContext) { val apiResourceList = APIResourceListBuilder() - //.withApiVersion("v1") - //.withGroupVersion("") - //.withKind("List") .addNewResource() - //.withGroup(context.group) .withName(context.plural) .withKind(context.kind) .withNamespaced(context.isNamespaceScoped) - //.withVersion(context.version) .endResource() .build() diff --git a/theodolite/src/test/kotlin/theodolite/benchmark/FileSystemResourceSetTest.kt b/theodolite/src/test/kotlin/theodolite/benchmark/FileSystemResourceSetTest.kt index bd20caf2712240bc671cc21920499e279891e1e1..6a31875d00c8f578dcc475c3de21e130c595f673 100644 --- a/theodolite/src/test/kotlin/theodolite/benchmark/FileSystemResourceSetTest.kt +++ b/theodolite/src/test/kotlin/theodolite/benchmark/FileSystemResourceSetTest.kt @@ -8,12 +8,9 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesServer import io.quarkus.test.junit.QuarkusTest import io.quarkus.test.kubernetes.client.KubernetesTestServer import io.quarkus.test.kubernetes.client.WithKubernetesTestServer -import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.* import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.io.TempDir import registerResource import theodolite.model.crd.BenchmarkCRD diff --git a/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt b/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt index 59864f55262bbafa1445fa0757f98bf5ade30861..ba65356b65b6ac23ca56c268bb003815917cf162 100644 --- a/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt +++ b/theodolite/src/test/kotlin/theodolite/execution/operator/StateHandlerTest.kt @@ -11,10 +11,8 @@ 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.resourceLoader.K8sResourceLoaderFromFile import theodolite.model.crd.ExecutionCRD import theodolite.model.crd.ExecutionState -import java.time.Duration @QuarkusTest @WithKubernetesTestServer diff --git a/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt b/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt index dca8264744568218552af527654cf49b3ac45ddd..ee80d55caf995642f6fff04cfeeb66bc08ab93d3 100644 --- a/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt +++ b/theodolite/src/test/kotlin/theodolite/k8s/K8sManagerTest.kt @@ -26,7 +26,6 @@ internal class K8sManagerTest { private final val resourceName = "test-resource" private final val metadata: ObjectMeta = ObjectMetaBuilder().withName(resourceName).build() - val defaultDeployment: Deployment = DeploymentBuilder() .withMetadata(metadata) .withNewSpec() diff --git a/theodolite/src/test/kotlin/theodolite/k8s/K8sResourceLoaderTest.kt b/theodolite/src/test/kotlin/theodolite/k8s/K8sResourceLoaderTest.kt deleted file mode 100644 index 64607268722996c48b016a93daf480f9db9721ab..0000000000000000000000000000000000000000 --- a/theodolite/src/test/kotlin/theodolite/k8s/K8sResourceLoaderTest.kt +++ /dev/null @@ -1,110 +0,0 @@ -package theodolite.k8s - -import io.fabric8.kubernetes.api.model.ConfigMap -import io.fabric8.kubernetes.api.model.Service -import io.fabric8.kubernetes.api.model.apps.Deployment -import io.fabric8.kubernetes.api.model.apps.StatefulSet -import io.fabric8.kubernetes.client.server.mock.KubernetesServer -import io.quarkus.test.junit.QuarkusTest -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile - -@QuarkusTest -@Deprecated("Since Resource Loaders are deprecated") -@Disabled -class K8sResourceLoaderTest { - private final val server = KubernetesServer(false, true) - private final val testResourcePath = "./src/test/resources/k8s-resource-files/" - - @BeforeEach - fun setUp() { - server.before() - } - - @AfterEach - fun tearDown() { - server.after() - } - - @Test - @DisplayName("Test loading of Deployments") - fun loadDeploymentTest() { - val loader = K8sResourceLoaderFromFile(server.client) - val resource = loader.loadK8sResource("Deployment", testResourcePath + "test-deployment.yaml") - - assertTrue(resource is Deployment) - assertTrue(resource.toString().contains("name=test-deployment")) - } - - @Test - @DisplayName("Test loading of StatefulSet") - fun loadStatefulSetTest() { - val loader = K8sResourceLoaderFromFile(server.client) - val resource = loader.loadK8sResource("StatefulSet", testResourcePath + "test-statefulset.yaml") - - assertTrue(resource is StatefulSet) - assertTrue(resource.toString().contains("name=test-statefulset")) - } - - @Test - @DisplayName("Test loading of Service") - fun loadServiceTest() { - val loader = K8sResourceLoaderFromFile(server.client) - val resource = loader.loadK8sResource("Service", testResourcePath + "test-service.yaml") - - assertTrue(resource is Service) - assertTrue(resource.toString().contains("name=test-service")) - } - - @Test - @DisplayName("Test loading of ConfigMap") - fun loadConfigMapTest() { - val loader = K8sResourceLoaderFromFile(server.client) - val resource = loader.loadK8sResource("ConfigMap", testResourcePath + "test-configmap.yaml") - - assertTrue(resource is ConfigMap) - assertTrue(resource.toString().contains("name=test-configmap")) - } - - @Test - @DisplayName("Test loading of ServiceMonitors") - fun loadServiceMonitorTest() { - val loader = K8sResourceLoaderFromFile(server.client) - val resource = loader.loadK8sResource("ServiceMonitor", testResourcePath + "test-service-monitor.yaml") - - assertTrue(resource is CustomResourceWrapper) - if (resource is CustomResourceWrapper) { - assertEquals("test-service-monitor", resource.getName()) - - } - } - - @Test - @DisplayName("Test loading of Executions") - fun loadExecutionTest() { - val loader = K8sResourceLoaderFromFile(server.client) - val resource = loader.loadK8sResource("Execution", testResourcePath + "test-execution.yaml") - - assertTrue(resource is CustomResourceWrapper) - if (resource is CustomResourceWrapper) { - assertEquals("example-execution", resource.getName()) - - } - } - - @Test - @DisplayName("Test loading of Benchmarks") - fun loadBenchmarkTest() { - val loader = K8sResourceLoaderFromFile(server.client) - val resource = loader.loadK8sResource("Benchmark", testResourcePath + "test-benchmark.yaml") - - assertTrue(resource is CustomResourceWrapper) - if (resource is CustomResourceWrapper) { - assertEquals("example-benchmark", resource.getName()) - - } - } - -} \ No newline at end of file diff --git a/theodolite/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt b/theodolite/src/test/kotlin/theodolite/patcher/ResourceLimitPatcherTest.kt similarity index 86% rename from theodolite/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt rename to theodolite/src/test/kotlin/theodolite/patcher/ResourceLimitPatcherTest.kt index a4bf68ac2747015a6b4f5670b7b8e87ce0365322..2769f2fef607a03d820b0821969db98894944cb3 100644 --- a/theodolite/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt +++ b/theodolite/src/test/kotlin/theodolite/patcher/ResourceLimitPatcherTest.kt @@ -1,14 +1,12 @@ -package theodolite +package theodolite.patcher -import io.fabric8.kubernetes.api.model.apps.Deployment -import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.server.mock.KubernetesServer import io.quarkus.test.junit.QuarkusTest import io.quarkus.test.kubernetes.client.KubernetesTestServer import io.quarkus.test.kubernetes.client.WithKubernetesTestServer import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile import theodolite.patcher.PatcherFactory import theodolite.util.PatcherDefinition @@ -24,9 +22,9 @@ import theodolite.util.PatcherDefinition */ @QuarkusTest @WithKubernetesTestServer +@Disabled class ResourceLimitPatcherTest { - //val testPath = "./src/test/resources/" - //val loader = K8sResourceLoaderFromFile(DefaultKubernetesClient().inNamespace("")) + val patcherFactory = PatcherFactory() @KubernetesTestServer @@ -36,12 +34,11 @@ class ResourceLimitPatcherTest { val cpuValue = "50m" val memValue = "3Gi" val k8sResource = server.client.apps().deployments().load(javaClass.getResourceAsStream(fileName)).get() - //val k8sResource = loader.loadK8sResource("Deployment", testPath + fileName) as Deployment val defCPU = PatcherDefinition() defCPU.resource = "/cpu-memory-deployment.yaml" defCPU.type = "ResourceLimitPatcher" - defCPU.properties = mutableMapOf( + defCPU.properties = mapOf( "limitedResource" to "cpu", "container" to "application" ) @@ -49,7 +46,7 @@ class ResourceLimitPatcherTest { val defMEM = PatcherDefinition() defMEM.resource = "/cpu-memory-deployment.yaml" defMEM.type = "ResourceLimitPatcher" - defMEM.properties = mutableMapOf( + defMEM.properties = mapOf( "limitedResource" to "memory", "container" to "uc-application" ) diff --git a/theodolite/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt b/theodolite/src/test/kotlin/theodolite/patcher/ResourceRequestPatcherTest.kt similarity index 85% rename from theodolite/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt rename to theodolite/src/test/kotlin/theodolite/patcher/ResourceRequestPatcherTest.kt index 7052a8be0a56d7619a9258d73c650c6a4c94fb00..dba91eb65d4474d38f64d7fdd7f7ab981f8eb30f 100644 --- a/theodolite/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt +++ b/theodolite/src/test/kotlin/theodolite/patcher/ResourceRequestPatcherTest.kt @@ -1,15 +1,11 @@ -package theodolite +package theodolite.patcher -import io.fabric8.kubernetes.api.model.apps.Deployment -import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.server.mock.KubernetesServer import io.quarkus.test.junit.QuarkusTest import io.quarkus.test.kubernetes.client.KubernetesTestServer import io.quarkus.test.kubernetes.client.WithKubernetesTestServer import io.smallrye.common.constraint.Assert.assertTrue import org.junit.jupiter.api.Test -import theodolite.k8s.resourceLoader.K8sResourceLoaderFromFile -import theodolite.patcher.PatcherFactory import theodolite.util.PatcherDefinition /** @@ -29,20 +25,17 @@ class ResourceRequestPatcherTest { @KubernetesTestServer private lateinit var server: KubernetesServer - //val testPath = "./src/test/resources/" - //val loader = K8sResourceLoaderFromFile(DefaultKubernetesClient().inNamespace("")) val patcherFactory = PatcherFactory() fun applyTest(fileName: String) { val cpuValue = "50m" val memValue = "3Gi" val k8sResource = server.client.apps().deployments().load(javaClass.getResourceAsStream(fileName)).get() - // loader.loadK8sResource("Deployment", testPath + fileName) as Deployment val defCPU = PatcherDefinition() defCPU.resource = "/cpu-memory-deployment.yaml" defCPU.type = "ResourceRequestPatcher" - defCPU.properties = mutableMapOf( + defCPU.properties = mapOf( "requestedResource" to "cpu", "container" to "application" ) @@ -50,7 +43,7 @@ class ResourceRequestPatcherTest { val defMEM = PatcherDefinition() defMEM.resource = "/cpu-memory-deployment.yaml" defMEM.type = "ResourceRequestPatcher" - defMEM.properties = mutableMapOf( + defMEM.properties = mapOf( "requestedResource" to "memory", "container" to "application" )