diff --git a/execution/infrastructure/random-scheduler/Dockerfile b/execution/infrastructure/random-scheduler/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..45f8ae9632022b458853013c1a52370c364e0002 --- /dev/null +++ b/execution/infrastructure/random-scheduler/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.12 + +RUN apk update && apk add bash curl jq +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 \ + && chmod +x ./kubectl \ + && mv ./kubectl /usr/local/bin/kubectl + +ADD schedule.sh /bin/schedule + +CMD /bin/schedule diff --git a/execution/infrastructure/random-scheduler/README.md b/execution/infrastructure/random-scheduler/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2d8da30a30923ccdf2c0d42afa9dd8dd1b5e475b --- /dev/null +++ b/execution/infrastructure/random-scheduler/README.md @@ -0,0 +1,12 @@ +# Theodolite Random Scheduler +This directory contains the Theodolite Random Scheduler that schedules pods on random nodes. + +## Build and Push +Run the following commands + +- `docker build -t theodolite-random-scheduler .` +- `docker tag theodolite-random-scheduler <user>/theodolite-random-scheduler` +- `docker push <user>/theodolite-random-scheduler` + +## Deployment +Deploy the `deployment.yaml` file into Kubernetes. Note, that the `TARGET_NAMESPACE` environment variable specifies the operating namespace of the random scheduler. \ No newline at end of file diff --git a/execution/infrastructure/random-scheduler/deployment.yaml b/execution/infrastructure/random-scheduler/deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..84e2c25933f3315256afd634ceeb7af6a1e405d9 --- /dev/null +++ b/execution/infrastructure/random-scheduler/deployment.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: random-scheduler + labels: + app: random-scheduler + namespace: kube-system +spec: + replicas: 1 + selector: + matchLabels: + app: random-scheduler + template: + metadata: + labels: + app: random-scheduler + spec: + serviceAccount: random-scheduler + containers: + - name: random-scheduler + image: theodolite/random-scheduler:latest + imagePullPolicy: Always + env: + - name: TARGET_NAMESPACE + value: default diff --git a/execution/infrastructure/random-scheduler/rbac.yaml b/execution/infrastructure/random-scheduler/rbac.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ba463cc54a575730cacac6b905603892572b11ec --- /dev/null +++ b/execution/infrastructure/random-scheduler/rbac.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + namespace: kube-system + name: random-scheduler + labels: + app: random-scheduler + component: random-scheduler +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: random-scheduler +subjects: +- kind: ServiceAccount + name: random-scheduler + namespace: kube-system +roleRef: + kind: ClusterRole + apiGroup: rbac.authorization.k8s.io + name: system:kube-scheduler \ No newline at end of file diff --git a/execution/infrastructure/random-scheduler/schedule.sh b/execution/infrastructure/random-scheduler/schedule.sh new file mode 100755 index 0000000000000000000000000000000000000000..e2e10c0abbdd06da5f5075cd21851331ffb593fe --- /dev/null +++ b/execution/infrastructure/random-scheduler/schedule.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# 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 + 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 '"')) + 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'"}}' 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