Skip to content
Snippets Groups Projects
Commit 06e82962 authored by Sören Henning's avatar Sören Henning
Browse files

Minor code quality improvements

parent 4c846e8c
No related branches found
No related tags found
No related merge requests found
Pipeline #8646 passed
......@@ -21,16 +21,13 @@ class ConfigOverrideModifier(val execution: BenchmarkExecution, val resources: L
labelValue: String,
labelName: String
) {
val additionalConfigOverrides = mutableListOf<ConfigurationOverride>()
resources.forEach {
run {
val configurationOverride = ConfigurationOverride()
configurationOverride.patcher = PatcherDefinition()
configurationOverride.patcher.type = "LabelPatcher"
configurationOverride.patcher.properties = mutableMapOf("variableName" to labelName)
configurationOverride.patcher.resource = it
configurationOverride.value = labelValue
additionalConfigOverrides.add(configurationOverride)
val additionalConfigOverrides = resources.map {
ConfigurationOverride().apply {
this.patcher = PatcherDefinition()
this.patcher.type = "LabelPatcher"
this.patcher.properties = mapOf("variableName" to labelName)
this.patcher.resource = it
this.value = labelValue
}
}
execution.configOverrides.addAll(additionalConfigOverrides)
......
......
......@@ -24,15 +24,14 @@ class DataVolumeLoadGeneratorReplicaPatcher(
return resources.flatMap { patchSingeResource(it, value)}
}
fun patchSingeResource(k8sResource: HasMetadata, value: String): List<HasMetadata> {
var resource = k8sResource
private fun patchSingeResource(k8sResource: HasMetadata, value: String): List<HasMetadata> {
// calculate number of load generator instances and load per instance
val load = Integer.parseInt(value)
val loadGenInstances = (load + maxVolume - 1) / maxVolume
val loadPerInstance = load / loadGenInstances
// Patch instance values and load value of generators
val resourceList = ReplicaPatcher().patch(listOf(resource), loadGenInstances.toString())
val resourceList = ReplicaPatcher().patch(listOf(k8sResource), loadGenInstances.toString())
return EnvVarPatcher(this.container, this.variableName).patch(resourceList, loadPerInstance.toString())
}
}
......@@ -3,13 +3,13 @@ package rocks.theodolite.kubernetes.patcher
import io.fabric8.kubernetes.api.model.HasMetadata
class PatchHandler {
companion object {
private fun getResourcesToPatch(resources: MutableMap<String, List<HasMetadata>>, patcherDefinition: PatcherDefinition): List<HasMetadata> {
private fun getResourcesToPatch(resources: Map<String, List<HasMetadata>>, patcherDefinition: PatcherDefinition): List<HasMetadata> {
return resources[patcherDefinition.resource]
?: throw InvalidPatcherConfigurationException("Could not find resource ${patcherDefinition.resource}")
}
fun patchResource(
resources: MutableMap<String, List<HasMetadata>>,
resources: Map<String, List<HasMetadata>>,
patcherDefinition: PatcherDefinition,
value: String,
): List<HasMetadata> {
......
......
......@@ -29,7 +29,7 @@ class ResourceLimitPatcher(
}
}
else -> {
throw InvalidPatcherConfigurationException("ResourceLimitPatcher is not applicable for $resource")
throw InvalidPatcherConfigurationException("ResourceLimitPatcher is not applicable for $resource.")
}
}
return resource
......
......
......@@ -29,7 +29,7 @@ class ResourceRequestPatcher(
}
}
else -> {
throw InvalidPatcherConfigurationException("ResourceRequestPatcher is not applicable for $resource")
throw InvalidPatcherConfigurationException("ResourceRequestPatcher is not applicable for $resource.")
}
}
return resource
......
......
......@@ -13,7 +13,6 @@ class TemplateLabelPatcher(
val variableName: String) :
AbstractPatcher() {
override fun patchSingleResource(resource: HasMetadata, value: String): HasMetadata {
when (resource) {
is Deployment -> {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment