diff --git a/theodolite/src/main/kotlin/theodolite/patcher/DataVolumeLoadGeneratorReplicaPatcher.kt b/theodolite/src/main/kotlin/theodolite/patcher/DataVolumeLoadGeneratorReplicaPatcher.kt new file mode 100644 index 0000000000000000000000000000000000000000..f797fc870d3fd5ca939c8ddc3ee5ec84f8cfadea --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/patcher/DataVolumeLoadGeneratorReplicaPatcher.kt @@ -0,0 +1,31 @@ +package theodolite.patcher + +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.apps.Deployment + +/** + * The DataVolumeLoadGeneratorReplicaPatcher allows to modify the value of an environment variable + * + * @property k8sResource Kubernetes resource to be patched. + * @property container Container to be patched. + * @property variableName Name of the environment variable to be patched. + */ +class DataVolumeLoadGeneratorReplicaPatcher( + private val k8sResource: KubernetesResource, + private val maxVolume: String, + container: String, + variableName: String +) : EnvVarPatcher(k8sResource, container, variableName) { + + override fun <String> patch(value: String) { + if (k8sResource is Deployment) { + if (value is kotlin.String) { + val load = value.toInt() + val loadGenInstances = (load + maxVolume.toInt() - 1) / maxVolume.toInt() + this.k8sResource.spec.replicas = loadGenInstances + val loadPerInstance = load / loadGenInstances + super.patch(loadPerInstance.toString()) + } + } + } +} diff --git a/theodolite/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt b/theodolite/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt index 416aec74a3af9b74594f5e6cd018682bf91cbf63..080afb055c0877bac0e767163dc5a028d535c836 100644 --- a/theodolite/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt +++ b/theodolite/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt @@ -12,7 +12,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment * @property container Container to be patched. * @property variableName Name of the environment variable to be patched. */ -class EnvVarPatcher( +open class EnvVarPatcher( private val k8sResource: KubernetesResource, private val container: String, private val variableName: String diff --git a/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt b/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt index 29723355ce23810c709fe4537242d1fd7e195d25..01a104cbdb4c916ff4cc8c404fbebd8966a908fa 100644 --- a/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt +++ b/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt @@ -48,6 +48,12 @@ class PatcherFactory { k8sResource = resource, loadGenMaxRecords = patcherDefinition.properties["loadGenMaxRecords"]!! ) + "DataVolumeLoadGeneratorReplicaPatcher" -> DataVolumeLoadGeneratorReplicaPatcher( + k8sResource = resource, + maxVolume = patcherDefinition.properties["maxVolume"]!!, + container = patcherDefinition.properties["container"]!!, + variableName = patcherDefinition.properties["variableName"]!! + ) "EnvVarPatcher" -> EnvVarPatcher( k8sResource = resource, container = patcherDefinition.properties["container"]!!,