diff --git a/execution/infrastructure/random-scheduler/Dockerfile b/execution/infrastructure/random-scheduler/Dockerfile index fadb231bda242977ec6b0aed1d8bba4f5394252d..9619d0bace1ee15f6d532d4a4b24cd4bb27eab04 100644 --- a/execution/infrastructure/random-scheduler/Dockerfile +++ b/execution/infrastructure/random-scheduler/Dockerfile @@ -1,9 +1,8 @@ -FROM ubuntu:bionic +FROM alpine:3.12 -RUN apt-get update -RUN apt-get dist-upgrade +RUN apk update -RUN apt-get install -y curl jq +RUN apk add curl jq bash RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl diff --git a/execution/infrastructure/random-scheduler/schedule.sh b/execution/infrastructure/random-scheduler/schedule.sh index 2eec0f18c1e1a70f1d541f2062588f984a853858..e2e10c0abbdd06da5f5075cd21851331ffb593fe 100755 --- a/execution/infrastructure/random-scheduler/schedule.sh +++ b/execution/infrastructure/random-scheduler/schedule.sh @@ -1,7 +1,8 @@ #!/bin/bash -KUBE_API_SERVER=($(kubectl cluster-info | grep 'Kubernetes master' | awk '/http/ {print $NF}' | awk -F : '{print $1$2}' | awk '{ gsub(/\/\//, "://"); print }')) -echo "K8's API server: $KUBE_API_SERVER" +# use kubectl in proxy mode in order to allow curl requesting the k8's api server +kubectl proxy --port 8080 & + echo "Target Namespace: $TARGET_NAMESPACE" while true; do @@ -10,7 +11,7 @@ do NODES=($(kubectl get nodes -o json | jq '.items[].metadata.name' | tr -d '"')) NUMNODES=${#NODES[@]} CHOSEN=${NODES[$[$RANDOM % $NUMNODES]]} - curl --insecure --header "Content-Type:application/json" --request POST --data '{"apiVersion":"v1", "kind": "Binding", "metadata": {"name": "'$PODNAME'"}, "target": {"apiVersion": "v1", "kind": "Node", "name": "'$CHOSEN'"}}' https://10.96.0.1/api/v1/namespaces/$TARGET_NAMESPACE/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'"}}' localhost:8080/api/v1/namespaces/$TARGET_NAMESPACE/pods/$PODNAME/binding/ echo "Assigned $PODNAME to $CHOSEN" done sleep 1 diff --git a/execution/infrastructure/random-scheduler/test.yaml b/execution/infrastructure/random-scheduler/test.yaml deleted file mode 100644 index 9104a0968e7c0accc1889211c2447b6250137b8a..0000000000000000000000000000000000000000 --- a/execution/infrastructure/random-scheduler/test.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 -kind: Deployment -metadata: - name: nginx-deployment -spec: - selector: - matchLabels: - app: nginx - replicas: 2 # tells deployment to run 2 pods matching the template - template: - metadata: - labels: - app: nginx - spec: - schedulerName: random-scheduler - containers: - - name: nginx - image: nginx:1.14.2 - ports: - - containerPort: 80 \ No newline at end of file