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

Clean up code

parent 74eb98c6
Branches
Tags
No related merge requests found
Showing with 15 additions and 32 deletions
......@@ -16,22 +16,22 @@ import io.fabric8.kubernetes.api.model.HasMetadata
*/
class DataVolumeLoadGeneratorReplicaPatcher(
private val maxVolume: Int,
private val container: String,
private val variableName: String
) : Patcher {
val container: String,
val variableName: String
) : AbstractPatcher() {
override fun patch(resources: List<HasMetadata>, value: String) : List<HasMetadata> {
return resources.flatMap { patchSingeResource(it, value)}
}
private val envVarPatcher = EnvVarPatcher(container, variableName)
private val replicaPatcher = ReplicaPatcher()
private fun patchSingeResource(k8sResource: HasMetadata, value: String): List<HasMetadata> {
override fun patchSingleResource(resource: HasMetadata, value: String): 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(k8sResource), loadGenInstances.toString())
return EnvVarPatcher(this.container, this.variableName).patch(resourceList, loadPerInstance.toString())
return this.envVarPatcher.patchSingleResource(
replicaPatcher.patchSingleResource(resource, loadGenInstances.toString()),
loadPerInstance.toString())
}
}
......@@ -10,15 +10,7 @@ import io.fabric8.kubernetes.client.utils.Serialization
*
* @param container Container to be patched.
*/
class ImagePatcher(
private val container: String) :
AbstractPatcher() {
override fun patch(resources: List<HasMetadata>, value: String) : List<HasMetadata> {
return resources
.map { Serialization.clone(it) }
.map { patchSingleResource(it, value as kotlin.String) }
}
class ImagePatcher(private val container: String) : AbstractPatcher() {
override fun patchSingleResource(resource: HasMetadata, value: String): HasMetadata {
if (resource is Deployment) {
......
......@@ -8,10 +8,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment
*
* @param variableName The `label-key` of the node for which the `label-value` is to be patched.
*/
class NodeSelectorPatcher(
private val variableName: String) :
AbstractPatcher() {
class NodeSelectorPatcher(private val variableName: String) : AbstractPatcher() {
override fun patchSingleResource(resource: HasMetadata, value: String): HasMetadata {
if (resource is Deployment) {
......
......@@ -5,7 +5,7 @@ class PatchHandler {
companion object {
private fun getResourcesToPatch(resources: Map<String, List<HasMetadata>>, patcherDefinition: PatcherDefinition): List<HasMetadata> {
return resources[patcherDefinition.resource]
?: throw InvalidPatcherConfigurationException("Could not find resource ${patcherDefinition.resource}")
?: throw InvalidPatcherConfigurationException("Could not find resource ${patcherDefinition.resource}.")
}
fun patchResource(
......
......@@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.apps.Deployment
/**
* The Scheduler name [Patcher] make it possible to set the scheduler which should
* be used to deploy the given deployment.
* @param k8sResource Kubernetes resource to be patched.
*/
class SchedulerNamePatcher : AbstractPatcher() {
......
......@@ -3,9 +3,7 @@ package rocks.theodolite.kubernetes.patcher
import io.fabric8.kubernetes.api.model.HasMetadata
import io.fabric8.kubernetes.api.model.Service
class ServiceSelectorPatcher(
private var variableName: String
) : AbstractPatcher() {
class ServiceSelectorPatcher(private var variableName: String) : AbstractPatcher() {
override fun patchSingleResource(resource: HasMetadata, value: String): HasMetadata {
if (resource is Service) {
......
......@@ -9,9 +9,7 @@ import io.fabric8.kubernetes.api.model.apps.StatefulSet
*
* @property variableName The label which should be set
*/
class TemplateLabelPatcher(
val variableName: String) :
AbstractPatcher() {
class TemplateLabelPatcher(val variableName: String) : AbstractPatcher() {
override fun patchSingleResource(resource: HasMetadata, value: String): HasMetadata {
when (resource) {
......
......@@ -4,8 +4,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata
import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.api.model.apps.StatefulSet
class VolumesConfigMapPatcher(private var volumeName: String
) : AbstractPatcher() {
class VolumesConfigMapPatcher(private var volumeName: String) : AbstractPatcher() {
override fun patchSingleResource(resource: HasMetadata, value: String): HasMetadata {
if (resource is Deployment) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment