diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceLimitPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceLimitPatcher.kt index b31733e64935f7ea0677f1a209933bc55690e0bb..5001371821ace60d14f75c838f3679733158b8cd 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceLimitPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceLimitPatcher.kt @@ -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()) - } } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceRequestPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceRequestPatcher.kt index 249a5011c4b7f9b7d0fb25db158f1c574690a99b..ffb28db4531fefe51b3db87c0363f9fda489769a 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceRequestPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ResourceRequestPatcher.kt @@ -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 +}