diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/deprecated/DeploymentManager.kt similarity index 98% rename from theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt rename to theodolite-quarkus/src/main/kotlin/theodolite/deprecated/DeploymentManager.kt index af59c523633d448da96d533c819823b5be5215c7..20980a42893f696fa081cdcee725bda294adfe92 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/deprecated/DeploymentManager.kt @@ -1,4 +1,4 @@ -package theodolite.k8s +package theodolite.deprecated import io.fabric8.kubernetes.api.model.Container import io.fabric8.kubernetes.api.model.EnvVar diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt index 4984f9bfe130569fce2e9ba30fd39607343999d1..80eb2eee17e8df6c4e1b97b81ad69917b22d0cc5 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt @@ -6,7 +6,6 @@ import theodolite.benchmark.KubernetesBenchmark class TheodoliteYamlExecutor { fun run() { - // load the Benchmark context and the benchmark type var parser = YamlParser() val benchmarkContext = parser.parse("./../../../resources/main/yaml/testContext.yaml", BenchmarkContext::class.java) !! diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt index e326ad3fec4a36c44e41f1c137442b8c9550ea7f..6be09ce26770e7b4e535c3cd6dcb95073e0c05be 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt @@ -18,7 +18,7 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) { * @param path of the yaml file * @return service from fabric8 */ - fun loadService(path: String): Service { + private fun loadService(path: String): Service { return loadGenericRessource(path) { x: String -> client.services().load(x).get() } } @@ -27,7 +27,7 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) { * @param path of the yaml file * @return service from fabric8 */ - fun loadServiceMonitor(path: String): CustomResourceDefinition { + private fun loadServiceMonitor(path: String): CustomResourceDefinition { return loadGenericRessource(path) { x: String -> client.customResourceDefinitions().load(x).get() } } @@ -36,7 +36,7 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) { * @param path of the yaml file * @return Deployment from fabric8 */ - fun loadDeployment(path: String): Deployment { + private fun loadDeployment(path: String): Deployment { return loadGenericRessource(path) { x: String -> client.apps().deployments().load(x).get() } } @@ -45,7 +45,7 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) { * @param path of the yaml file * @return ConfigMap from fabric8 */ - fun loadConfigmap(path: String): ConfigMap { + private fun loadConfigmap(path: String): ConfigMap { return loadGenericRessource(path) { x: String -> client.configMaps().load(x).get() } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ImagePatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ImagePatcher.kt new file mode 100644 index 0000000000000000000000000000000000000000..3a7f39ccedd6c13bf5095b66d06c51c81eba9fe3 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ImagePatcher.kt @@ -0,0 +1,21 @@ +package theodolite.patcher + +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.Quantity +import io.fabric8.kubernetes.api.model.apps.Deployment +import io.fabric8.kubernetes.api.model.apps.StatefulSet + +class ImagePatcher(private val k8sResource: KubernetesResource, private val container: String, private val variableName: String): AbstractPatcher(k8sResource, container, variableName) { + + override fun <String> patch(value: String) { + if (k8sResource is Deployment) { + k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { + it.image = value as kotlin.String + } + } else if (k8sResource is StatefulSet) { + k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { + it.image = value as kotlin.String + } + } + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt index b3a63e2adb58b42b90131d76160d7842f86cc019..9fbbf98fe3801675671eae0fcd13d48f3e990a15 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt @@ -7,13 +7,13 @@ import java.lang.IllegalArgumentException class PatcherManager { private fun createK8sPatcher(patcherDefinition: PatcherDefinition, k8sResources: List<Pair<String, KubernetesResource>>): Patcher { + val resource = k8sResources.filter { it.first == patcherDefinition.resource}.map { resource -> resource.second }[0] return when(patcherDefinition.type) { - "ReplicaPatcher" -> ReplicaPatcher(k8sResources.filter { it.first == patcherDefinition.resource}.map { resource -> resource.second }[0]) - "EnvVarPatcher" -> EnvVarPatcher(k8sResources.filter { it.first == patcherDefinition.resource}.map { resource -> resource.second }[0], - patcherDefinition.container, - patcherDefinition.variableName) - "NodeSelectorPatcher" -> NodeSelectorPatcher(k8sResources.filter { it.first == patcherDefinition.resource }.map { resource -> resource.second }[0], - patcherDefinition.variableName) + "ReplicaPatcher" -> ReplicaPatcher(resource) + "EnvVarPatcher" -> EnvVarPatcher(resource, patcherDefinition.container, patcherDefinition.variableName) + "NodeSelectorPatcher" -> NodeSelectorPatcher(resource, patcherDefinition.variableName) + "ResourceLimitPatcher" -> ResourceLimitPatcher(resource, patcherDefinition.container, patcherDefinition.variableName) + "ResourceRequestPatcher" -> ResourceRequestPatcher(resource, patcherDefinition.container, patcherDefinition.variableName) else -> throw IllegalArgumentException("Patcher type ${patcherDefinition.type} not found") } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceLimitPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceLimitPatcher.kt new file mode 100644 index 0000000000000000000000000000000000000000..3ccc42a76a63ed5132100812359563fed5f30e98 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceLimitPatcher.kt @@ -0,0 +1,34 @@ +package theodolite.patcher + +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.Quantity +import io.fabric8.kubernetes.api.model.ResourceRequirements +import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder +import io.fabric8.kubernetes.api.model.apps.Deployment +import io.fabric8.kubernetes.api.model.apps.StatefulSet +import java.lang.IllegalStateException + +class ResourceLimitPatcher(private val k8sResource: KubernetesResource, private val container: String, private val variableName: String): AbstractPatcher(k8sResource, container, variableName) { + + override fun <String> patch(value: String) { + + if (k8sResource is Deployment) { + k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { + try { + if (it.resources.limits.isNullOrEmpty()) { + it.resources.limits = mapOf(variableName to Quantity(value as kotlin.String)) + } else { + val values = it.resources.limits + println(values) + values[variableName] = Quantity(value as kotlin.String) + it.resources.limits = values + } + } catch (e: IllegalStateException) { + val resource = ResourceRequirements() + resource.limits = mapOf(variableName to Quantity(value as kotlin.String)) + it.resources = resource + } + } + } + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceRequestPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceRequestPatcher.kt new file mode 100644 index 0000000000000000000000000000000000000000..249a5011c4b7f9b7d0fb25db158f1c574690a99b --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceRequestPatcher.kt @@ -0,0 +1,21 @@ +package theodolite.patcher + +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.Quantity +import io.fabric8.kubernetes.api.model.apps.Deployment +import io.fabric8.kubernetes.api.model.apps.StatefulSet + +class ResourceRequestPatcher(private val k8sResource: KubernetesResource, private val container: String, private val variableName: String): AbstractPatcher(k8sResource, container, variableName) { + + override fun <String> patch(value: String) { + if (k8sResource is Deployment) { + k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { + it.resources.requests.replace(variableName,Quantity(value as kotlin.String)) + } + } else if (k8sResource is StatefulSet) { + k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { + it.resources.requests.replace(variableName, Quantity(value as kotlin.String)) + } + } + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/aggregation-deployment.yaml b/theodolite-quarkus/src/main/resources/yaml/aggregation-deployment.yaml index 3963fa7f13577f7f9f3e98e0782180dfe4406150..79691e15f0c488ece44ace02a0a032332c958c19 100644 --- a/theodolite-quarkus/src/main/resources/yaml/aggregation-deployment.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/aggregation-deployment.yaml @@ -28,10 +28,6 @@ spec: value: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=5555" - name: COMMIT_INTERVAL_MS # Set as default for the applications value: "100" - resources: - limits: - memory: 4Gi - cpu: 1000m - name: prometheus-jmx-exporter image: "solsson/kafka-prometheus-jmx-exporter@sha256:6f82e2b0464f50da8104acd7363fb9b995001ddff77d248379f8788e78946143" command: diff --git a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml index 4b71fde4664c20b9dba69f9ff2e545e3a331b5b2..dffbe430e1a5114ab1a7bd3a2b9d08de1d8dc946 100644 --- a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml @@ -27,4 +27,16 @@ configOverrides: type: "NodeSelectorPatcher" resource: "aggregation-deployment.yaml" variableName: "env" - value: "prod" \ No newline at end of file + value: "prod" + - patcher: + type: "ResourceLimitPatcher" + resource: "aggregation-deployment.yaml" + container: "uc-application" + variableName: "cpu" + value: "50m" + - patcher: + type: "ResourceLimitPatcher" + resource: "aggregation-deployment.yaml" + container: "uc-application" + variableName: "memory" + value: "2Gi" \ No newline at end of file