Skip to content
Snippets Groups Projects
Commit f075528f authored by Lorenz Boguhn's avatar Lorenz Boguhn Committed by Sören Henning
Browse files

Fix RequestPatcher

parent 55d76f79
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!85Introduce new Benchmark class and Patcher,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
...@@ -16,22 +16,19 @@ class ResourceLimitPatcher( ...@@ -16,22 +16,19 @@ class ResourceLimitPatcher(
if (k8sResource is Deployment) { if (k8sResource is Deployment) {
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach {
try { try {
println("before: " + it.resources.limits.toString()) if (it.resources.limits.isEmpty()) {
println("$variableName to : $value")
if (it.resources.limits.isNullOrEmpty()) {
it.resources.limits = mapOf(variableName to Quantity(value as kotlin.String)) it.resources.limits = mapOf(variableName to Quantity(value as kotlin.String))
} else { } else {
val values = Quantity(value as kotlin.String) val values = mutableMapOf<kotlin.String, Quantity>()
it.resources.limits[variableName] = values it.resources.limits.forEach { entry -> values.put(entry.key, entry.value) }
values[variableName] = Quantity(value as kotlin.String)
it.resources.limits = values
} }
} catch (e: IllegalStateException) { } catch (e: IllegalStateException) {
val resource = ResourceRequirements() val resource = ResourceRequirements()
resource.limits = mapOf(variableName to Quantity(value as kotlin.String)) resource.limits = mapOf(variableName to Quantity(value as kotlin.String))
it.resources = resource it.resources = resource
} }
println("after " + it.resources.limits.toString())
} }
} }
} }
......
...@@ -2,20 +2,33 @@ package theodolite.patcher ...@@ -2,20 +2,33 @@ package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.KubernetesResource
import io.fabric8.kubernetes.api.model.Quantity import io.fabric8.kubernetes.api.model.Quantity
import io.fabric8.kubernetes.api.model.ResourceRequirements
import io.fabric8.kubernetes.api.model.apps.Deployment 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) { class ResourceRequestPatcher(
private val k8sResource: KubernetesResource,
private val container: String,
private val variableName: String
) : AbstractPatcher(k8sResource, container, variableName) {
override fun <String> patch(value: String) { override fun <String> patch(value: String) {
if (k8sResource is Deployment) { if (k8sResource is Deployment) {
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach {
it.resources.requests.replace(variableName,Quantity(value as kotlin.String)) try {
} if (it.resources.requests.isEmpty()) {
} else if (k8sResource is StatefulSet) { it.resources.requests = mapOf(variableName to Quantity(value as kotlin.String))
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { } else {
it.resources.requests.replace(variableName, Quantity(value as kotlin.String)) val values = mutableMapOf<kotlin.String, Quantity>()
it.resources.requests.forEach { entry -> values.put(entry.key, entry.value) }
values[variableName] = Quantity(value as kotlin.String)
it.resources.requests = values
}
} catch (e: IllegalStateException) {
val resource = ResourceRequirements()
resource.requests = mapOf(variableName to Quantity(value as kotlin.String))
it.resources = resource
}
} }
} }
} }
} }
\ 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