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

Merge branch 'master' of git.se.informatik.uni-kiel.de:she/theodolite into...

Merge branch 'master' of git.se.informatik.uni-kiel.de:she/theodolite into 240-make-resources-accessible-from-configmap
parents 7c1ee7c3 d7805178
No related branches found
No related tags found
1 merge request!171Introduce ResourceSets to make loading of resource files more flexible
This commit is part of merge request !171. Comments created here will be created in the context of that merge request.
...@@ -46,8 +46,7 @@ class K8sManager(private val client: NamespacedKubernetesClient) { ...@@ -46,8 +46,7 @@ class K8sManager(private val client: NamespacedKubernetesClient) {
this.client.apps().deployments().delete(resource) this.client.apps().deployments().delete(resource)
ResourceByLabelHandler(client = client) ResourceByLabelHandler(client = client)
.blockUntilPodsDeleted( .blockUntilPodsDeleted(
labelName = "app", matchLabels = resource.spec.selector.matchLabels
labelValue = resource.spec.selector.matchLabels["app"]!!
) )
logger.info { "Deployment '${resource.metadata.name}' deleted." } logger.info { "Deployment '${resource.metadata.name}' deleted." }
} }
...@@ -59,8 +58,7 @@ class K8sManager(private val client: NamespacedKubernetesClient) { ...@@ -59,8 +58,7 @@ class K8sManager(private val client: NamespacedKubernetesClient) {
this.client.apps().statefulSets().delete(resource) this.client.apps().statefulSets().delete(resource)
ResourceByLabelHandler(client = client) ResourceByLabelHandler(client = client)
.blockUntilPodsDeleted( .blockUntilPodsDeleted(
labelName = "app", matchLabels = resource.spec.selector.matchLabels
labelValue = resource.spec.selector.matchLabels["app"]!!
) )
logger.info { "StatefulSet '$resource.metadata.name' deleted." } logger.info { "StatefulSet '$resource.metadata.name' deleted." }
} }
......
...@@ -99,16 +99,16 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) { ...@@ -99,16 +99,16 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) {
* @param [labelName] the label name * @param [labelName] the label name
* @param [labelValue] the value of this label * @param [labelValue] the value of this label
* */ * */
fun blockUntilPodsDeleted(labelName: String, labelValue: String) { fun blockUntilPodsDeleted(matchLabels: MutableMap<String, String>) {
while ( while (
!this.client !this.client
.pods() .pods()
.withLabel("$labelName=$labelValue") .withLabels(matchLabels)
.list() .list()
.items .items
.isNullOrEmpty() .isNullOrEmpty()
) { ) {
logger.info { "Wait for pods with label $labelName=$labelValue to be deleted." } logger.info { "Wait for pods with label ${matchLabels.toString()} to be deleted." }
Thread.sleep(1000) Thread.sleep(1000)
} }
} }
......
package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource
/**
* The DataVolumeLoadGeneratorReplicaPatcher takes the total load that should be generated
* and computes the number of instances needed for this load based on the `maxVolume`
* ((load + maxVolume - 1) / maxVolume) and calculates the load per instance
* (loadPerInstance = load / instances).
* The number of instances are set for the load generator and the given variable is set to the
* load per instance.
*
* @property k8sResource Kubernetes resource to be patched.
* @property maxVolume per load generator instance
* @property container Container to be patched.
* @property variableName Name of the environment variable to be patched.
*/
class DataVolumeLoadGeneratorReplicaPatcher(
k8sResource: KubernetesResource,
private val maxVolume: Int,
container: String,
variableName: String
) : AbstractPatcher(k8sResource) {
private val replicaPatcher = ReplicaPatcher(k8sResource)
private val envVarPatcher = EnvVarPatcher(k8sResource, container, variableName)
override fun <T> patch(value: T) {
// calculate number of load generator instances and load per instance
val load = Integer.parseInt(value.toString())
val loadGenInstances = (load + maxVolume - 1) / maxVolume
val loadPerInstance = load / loadGenInstances
// Patch instance values and load value of generators
replicaPatcher.patch(loadGenInstances.toString())
envVarPatcher.patch(loadPerInstance.toString())
}
}
...@@ -48,6 +48,12 @@ class PatcherFactory { ...@@ -48,6 +48,12 @@ class PatcherFactory {
k8sResource = resource, k8sResource = resource,
loadGenMaxRecords = patcherDefinition.properties["loadGenMaxRecords"]!! loadGenMaxRecords = patcherDefinition.properties["loadGenMaxRecords"]!!
) )
"DataVolumeLoadGeneratorReplicaPatcher" -> DataVolumeLoadGeneratorReplicaPatcher(
k8sResource = resource,
maxVolume = patcherDefinition.properties["maxVolume"]!!.toInt(),
container = patcherDefinition.properties["container"]!!,
variableName = patcherDefinition.properties["variableName"]!!
)
"EnvVarPatcher" -> EnvVarPatcher( "EnvVarPatcher" -> EnvVarPatcher(
k8sResource = resource, k8sResource = resource,
container = patcherDefinition.properties["container"]!!, container = patcherDefinition.properties["container"]!!,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment