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 ...@@ -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 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>) { private fun setContainerEnv(container: Container, map: Map<String, String>) {
map.forEach { k, v -> map.forEach { (k, v) ->
// filter for mathing name and set value // filter for matching name and set value
val x = container.env.filter { envVar -> envVar.name == k } val x = container.env.filter { envVar -> envVar.name == k }
if (x.isEmpty()) { if (x.isEmpty()) {
......
package theodolite.patcher 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.apps.Deployment import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.api.model.apps.StatefulSet 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) { 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.image = value as kotlin.String it.image = imagePath as kotlin.String
} }
} else if (k8sResource is StatefulSet) { } else if (k8sResource is StatefulSet) {
k8sResource.spec.template.spec.containers.filter { it.name == container }.forEach { 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 ...@@ -8,25 +8,24 @@ import io.fabric8.kubernetes.api.model.apps.Deployment
class ResourceLimitPatcher( class ResourceLimitPatcher(
private val k8sResource: KubernetesResource, private val k8sResource: KubernetesResource,
private val container: String, private val container: String,
private val variableName: String private val limitedResource: String
) : AbstractPatcher(k8sResource, container, variableName) { ) : AbstractPatcher(k8sResource, container, limitedResource) {
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 {
try { try {
if (it.resources.limits.isEmpty()) { 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 { } else {
val values = mutableMapOf<kotlin.String, Quantity>() val values = mutableMapOf<kotlin.String, Quantity>()
it.resources.limits.forEach { entry -> values.put(entry.key, entry.value) } it.resources.limits.forEach { entry -> values[entry.key] = entry.value }
values[variableName] = Quantity(value as kotlin.String) values[limitedResource] = Quantity(value as kotlin.String)
it.resources.limits = values 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(limitedResource to Quantity(value as kotlin.String))
it.resources = resource it.resources = resource
} }
} }
......
...@@ -8,24 +8,24 @@ import io.fabric8.kubernetes.api.model.apps.Deployment ...@@ -8,24 +8,24 @@ import io.fabric8.kubernetes.api.model.apps.Deployment
class ResourceRequestPatcher( class ResourceRequestPatcher(
private val k8sResource: KubernetesResource, private val k8sResource: KubernetesResource,
private val container: String, private val container: String,
private val variableName: String private val requestedResource: String
) : AbstractPatcher(k8sResource, container, variableName) { ) : AbstractPatcher(k8sResource, container, requestedResource) {
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 {
try { try {
if (it.resources.requests.isEmpty()) { 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 { } else {
val values = mutableMapOf<kotlin.String, Quantity>() val values = mutableMapOf<kotlin.String, Quantity>()
it.resources.requests.forEach { entry -> values.put(entry.key, entry.value) } it.resources.requests.forEach { entry -> values[entry.key] = entry.value }
values[variableName] = Quantity(value as kotlin.String) values[requestedResource] = Quantity(value as kotlin.String)
it.resources.requests = values it.resources.requests = values
} }
} catch (e: IllegalStateException) { } catch (e: IllegalStateException) {
val resource = ResourceRequirements() 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 it.resources = resource
} }
} }
......
...@@ -18,7 +18,7 @@ loadTypes: ...@@ -18,7 +18,7 @@ loadTypes:
container: "workload-generator" container: "workload-generator"
variableName: "NUM_SENSORS" variableName: "NUM_SENSORS"
kafkaConfig: kafkaConfig:
bootstrapSever: "localhost:31290" bootstrapServer: "localhost:31290"
topics: topics:
- name: "input" - name: "input"
partition: "1" 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