diff --git a/execution/infrastructure/random-scheduler/schedule.sh b/execution/infrastructure/random-scheduler/schedule.sh index e2e10c0abbdd06da5f5075cd21851331ffb593fe..06745354d061225cfc1b3a746d361036b647051b 100755 --- a/execution/infrastructure/random-scheduler/schedule.sh +++ b/execution/infrastructure/random-scheduler/schedule.sh @@ -8,11 +8,18 @@ while true; do for PODNAME in $(kubectl get pods -n $TARGET_NAMESPACE -o json | jq '.items[] | select(.spec.schedulerName == "random-scheduler") | select(.spec.nodeName == null) | .metadata.name' | tr -d '"'); do - NODES=($(kubectl get nodes -o json | jq '.items[].metadata.name' | tr -d '"')) + NODE_SELECTOR=$(kubectl get pod $PODNAME -n $TARGET_NAMESPACE -o json | jq -S 'if .spec.nodeSelector != null then .spec.nodeSelector else {} end') + NODES=($(kubectl get nodes -o json | jq --argjson nodeSelector "$NODE_SELECTOR" '.items[] | select(.metadata.labels | contains($nodeSelector)) | .metadata.name' | tr -d '"')) NUMNODES=${#NODES[@]} + if [ $NUMNODES -eq 0 ]; then + echo "No nodes found matching the node selector: $NODE_SELECTOR from pod $PODNAME" + echo "Pod $PODNAME cannot be scheduled." + continue; + fi + echo "Found $NUM_NODES suitable nodes for pod $PODNAME" CHOSEN=${NODES[$[$RANDOM % $NUMNODES]]} curl --header "Content-Type:application/json" --request POST --data '{"apiVersion":"v1", "kind": "Binding", "metadata": {"name": "'$PODNAME'"}, "target": {"apiVersion": "v1", "kind": "Node", "name": "'$CHOSEN'"}}' localhost:8080/api/v1/namespaces/$TARGET_NAMESPACE/pods/$PODNAME/binding/ echo "Assigned $PODNAME to $CHOSEN" done sleep 1 -done \ No newline at end of file +done diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt index 1a3e56bfe7aaf01526dc8ce4ed2c106383e1f8b7..dd391c599ad33fa0f6990ecc86ed1af5430cb695 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherFactory.kt @@ -22,6 +22,7 @@ class PatcherFactory { patcherDefinition.container, patcherDefinition.variableName ) + "SchedulerNamePatcher" -> SchedulerNamePatcher(resource) else -> throw IllegalArgumentException("Patcher type ${patcherDefinition.type} not found") } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/SchedulerNamePatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/SchedulerNamePatcher.kt new file mode 100644 index 0000000000000000000000000000000000000000..88d9a978f23c8c5612d2ad46df795b7e3ba8cd19 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/SchedulerNamePatcher.kt @@ -0,0 +1,12 @@ +package theodolite.patcher + +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.api.model.apps.Deployment + +class SchedulerNamePatcher(private val k8sResource: KubernetesResource): Patcher { + override fun <String> patch(value: String) { + if (k8sResource is Deployment) { + k8sResource.spec.template.spec.schedulerName = value as kotlin.String; + } + } +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml index a91d123628a03bb7fd82821d6f34d7bf1239c154..94c671008d0910be38ececd8558c689173b991ad 100644 --- a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml @@ -43,4 +43,8 @@ configOverrides: resource: "uc1-kstreams-deployment.yaml" container: "uc-application" variableName: "memory" - value: "2Gi" \ No newline at end of file + value: "2Gi" + - patcher: + type: "SchedulerNamePatcher" + resource: "uc1-kstreams-deployment.yaml" + value: "random-scheduler" \ No newline at end of file