Skip to content
Snippets Groups Projects
Commit 9bf2b5f6 authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

minor code enhancements

parent 6d419bdc
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,13 +16,13 @@ class EnvVarPatcher(private val k8sResource: KubernetesResource, private val con
}
/**
* Sets the ContainerEvironmentVariables, creates new if variable does not exist.
* Sets the ContainerEnvironmentVariables, creates new if variable does not exist.
* @param container - The Container
* @param map - Map of k=Name,v =Value of EnviromentVariables
* @param map - Map of k=Name,v =Value of EnvironmentVariables
*/
private fun setContainerEnv(container: Container, map: Map<String, String>) {
map.forEach { k, v ->
// filter for mathing name and set value
map.forEach { (k, v) ->
// filter for matching name and set value
val x = container.env.filter { envVar -> envVar.name == k }
if (x.isEmpty()) {
......
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) {
class ImagePatcher(private val k8sResource: KubernetesResource, private val container: String): AbstractPatcher(k8sResource, container) {
override fun <String> patch(value: String) {
override fun <String> patch(imagePath: String) {
if (k8sResource is Deployment) {
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach {
it.image = value as kotlin.String
it.image = imagePath as kotlin.String
}
} else if (k8sResource is StatefulSet) {
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach {
it.image = value as kotlin.String
it.image = imagePath as kotlin.String
}
}
}
......
......@@ -8,25 +8,24 @@ import io.fabric8.kubernetes.api.model.apps.Deployment
class ResourceLimitPatcher(
private val k8sResource: KubernetesResource,
private val container: String,
private val variableName: String
) : AbstractPatcher(k8sResource, container, variableName) {
private val limitedResource: String
) : AbstractPatcher(k8sResource, container, limitedResource) {
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.isEmpty()) {
it.resources.limits = mapOf(variableName to Quantity(value as kotlin.String))
it.resources.limits = mapOf(limitedResource to Quantity(value as kotlin.String))
} else {
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.forEach { entry -> values[entry.key] = entry.value }
values[limitedResource] = 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))
resource.limits = mapOf(limitedResource to Quantity(value as kotlin.String))
it.resources = resource
}
}
......
......@@ -8,24 +8,24 @@ import io.fabric8.kubernetes.api.model.apps.Deployment
class ResourceRequestPatcher(
private val k8sResource: KubernetesResource,
private val container: String,
private val variableName: String
) : AbstractPatcher(k8sResource, container, variableName) {
private val requestedResource: String
) : AbstractPatcher(k8sResource, container, requestedResource) {
override fun <String> patch(value: String) {
if (k8sResource is Deployment) {
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach {
try {
if (it.resources.requests.isEmpty()) {
it.resources.requests = mapOf(variableName to Quantity(value as kotlin.String))
it.resources.requests = mapOf(requestedResource 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.forEach { entry -> values[entry.key] = entry.value }
values[requestedResource] = 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))
resource.requests = mapOf(requestedResource to Quantity(value as kotlin.String))
it.resources = resource
}
}
......
......@@ -18,7 +18,7 @@ loadTypes:
container: "workload-generator"
variableName: "NUM_SENSORS"
kafkaConfig:
bootstrapSever: "localhost:31290"
bootstrapServer: "localhost:31290"
topics:
- name: "input"
partition: "1"
......
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