Skip to content
Snippets Groups Projects
Commit ce0153d0 authored by Simon Ehrenstein's avatar Simon Ehrenstein
Browse files

Prototype of random scheduling

parent 5c099bba
No related branches found
No related tags found
1 merge request!61Allow using a random scheduler
#!/bin/bash
SERVER=($(kubectl config view -o json | jq '.clusters[0].cluster.server'))
KUBE_API_KUBE_API_SERVER=($(kubectl config view -o json | jq '.clusters[0].cluster.server'))
while true;
do
echo "$(kubectl get pods -n default)"
for PODNAME in $(kubectl get pods -n default -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 '"'))
NUMNODES=${#NODES[@]}
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'"}}' $SERVER/api/v1/namespaces/default/pods/$PODNAME/binding/
curl --header "Content-Type:application/json" --request POST --data '{"apiVersion":"v1", "kind": "Binding", "metadata": {"name": "'$PODNAME'"}, "target": {"apiVersion": "v1", "kind": "Node", "name": "'$CHOSEN'"}}' $KUBE_API_SERVER/api/v1/namespaces/default/pods/$PODNAME/binding/
echo "Assigned $PODNAME to $CHOSEN"
done
sleep 1
done
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment