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(
if (k8sResource is Deployment) {
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach {
try {
println("before: " + it.resources.limits.toString())
println("$variableName to : $value")
if (it.resources.limits.isNullOrEmpty()) {
if (it.resources.limits.isEmpty()) {
it.resources.limits = mapOf(variableName to Quantity(value as kotlin.String))
} else {
val values = Quantity(value as kotlin.String)
it.resources.limits[variableName] = values
val values = mutableMapOf<kotlin.String, Quantity>()
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) {
val resource = ResourceRequirements()
resource.limits = mapOf(variableName to Quantity(value as kotlin.String))
it.resources = resource
}
println("after " + it.resources.limits.toString())
}
}
}
......
......@@ -2,20 +2,33 @@ 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.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) {
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))
try {
if (it.resources.requests.isEmpty()) {
it.resources.requests = mapOf(variableName to Quantity(value as kotlin.String))
} else {
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