Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 1 | // sets up a kubernetes cluster (using kind) |
| 2 | |
| 3 | def call(Map config) { |
| 4 | // note that I can't define this outside the function as there's no global scope in Groovy |
| 5 | def defaultConfig = [ |
| 6 | nodes: 1, |
| 7 | name: "kind-ci" |
| 8 | ] |
| 9 | |
| 10 | if (!config) { |
| 11 | config = [:] |
| 12 | } |
| 13 | |
| 14 | def cfg = defaultConfig + config |
| 15 | |
| 16 | println "Deploying Kind cluster with the following parameters: ${cfg}." |
| 17 | |
| 18 | // TODO support different configs |
| 19 | def data = """ |
| 20 | kind: Cluster |
| 21 | apiVersion: kind.x-k8s.io/v1alpha4 |
| 22 | nodes: |
Matteo Scandolo | 9b644ba | 2021-04-19 11:21:07 -0700 | [diff] [blame] | 23 | - role: worker |
| 24 | - role: worker |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 25 | - role: control-plane |
Matteo Scandolo | 9b644ba | 2021-04-19 11:21:07 -0700 | [diff] [blame] | 26 | kubeadmConfigPatches: |
| 27 | - | |
| 28 | kind: InitConfiguration |
| 29 | nodeRegistration: |
| 30 | kubeletExtraArgs: |
| 31 | node-labels: "ingress-ready=true" |
| 32 | extraPortMappings: |
| 33 | - containerPort: 80 |
| 34 | hostPort: 80 |
| 35 | protocol: TCP |
| 36 | - containerPort: 443 |
| 37 | hostPort: 443 |
| 38 | protocol: TCP |
| 39 | - containerPort: 30115 |
| 40 | hostPort: 30115 |
| 41 | - containerPort: 30120 |
| 42 | hostPort: 30120 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 43 | """ |
| 44 | writeFile(file: 'kind.cfg', text: data) |
| 45 | |
| 46 | // TODO skip cluster creation if cluster is already there |
| 47 | sh """ |
| 48 | mkdir -p $WORKSPACE/bin |
| 49 | |
| 50 | # download kind (should we add it to the base image?) |
| 51 | curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64 |
| 52 | chmod +x ./kind |
| 53 | mv ./kind $WORKSPACE/bin/kind |
| 54 | |
| 55 | # install voltctl |
| 56 | HOSTOS="\$(uname -s | tr "[:upper:]" "[:lower:"])" |
| 57 | HOSTARCH="\$(uname -m | tr "[:upper:]" "[:lower:"])" |
| 58 | if [ "\$HOSTARCH" == "x86_64" ]; then |
| 59 | HOSTARCH="amd64" |
| 60 | fi |
Hardik Windlass | abd342c | 2021-03-25 12:20:43 +0530 | [diff] [blame] | 61 | VC_VERSION="\$(curl --fail -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')" |
| 62 | curl -Lo $WORKSPACE/bin/voltctl https://github.com/opencord/voltctl/releases/download/v\$VC_VERSION/voltctl-\$VC_VERSION-\$HOSTOS-\$HOSTARCH |
Matteo Scandolo | 29597f0 | 2021-02-12 10:53:57 -0800 | [diff] [blame] | 63 | chmod +x $WORKSPACE/bin/voltctl |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 64 | |
| 65 | # start the kind cluster |
| 66 | kind create cluster --name ${cfg.name} --config kind.cfg |
| 67 | |
| 68 | # remove NoSchedule taint from nodes |
| 69 | for MNODE in \$(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do |
| 70 | kubectl taint node "\$MNODE" node-role.kubernetes.io/master:NoSchedule- |
| 71 | done |
| 72 | |
| 73 | mkdir -p $HOME/.volt |
| 74 | voltctl -s localhost:55555 config > $HOME/.volt/config |
| 75 | |
| 76 | mkdir -p $HOME/.kube |
| 77 | kind get kubeconfig --name ${cfg.name} > $HOME/.kube/config |
| 78 | |
| 79 | # add helm repositories |
| 80 | helm repo add onf https://charts.opencord.org |
| 81 | helm repo update |
| 82 | |
| 83 | # download kail |
| 84 | bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin" |
| 85 | """ |
| 86 | } |