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: |
| 23 | - role: control-plane |
| 24 | - role: worker |
| 25 | - role: worker |
| 26 | """ |
| 27 | writeFile(file: 'kind.cfg', text: data) |
| 28 | |
| 29 | // TODO skip cluster creation if cluster is already there |
| 30 | sh """ |
| 31 | mkdir -p $WORKSPACE/bin |
| 32 | |
| 33 | # download kind (should we add it to the base image?) |
| 34 | curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64 |
| 35 | chmod +x ./kind |
| 36 | mv ./kind $WORKSPACE/bin/kind |
| 37 | |
| 38 | # install voltctl |
| 39 | HOSTOS="\$(uname -s | tr "[:upper:]" "[:lower:"])" |
| 40 | HOSTARCH="\$(uname -m | tr "[:upper:]" "[:lower:"])" |
| 41 | if [ "\$HOSTARCH" == "x86_64" ]; then |
| 42 | HOSTARCH="amd64" |
| 43 | fi |
Matteo Scandolo | 29597f0 | 2021-02-12 10:53:57 -0800 | [diff] [blame] | 44 | curl -Lo $WORKSPACE/bin/voltctl https://github.com/opencord/voltctl/releases/download/v1.3.1/voltctl-1.3.1-\$HOSTOS-\$HOSTARCH |
| 45 | chmod +x $WORKSPACE/bin/voltctl |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 46 | |
| 47 | # start the kind cluster |
| 48 | kind create cluster --name ${cfg.name} --config kind.cfg |
| 49 | |
| 50 | # remove NoSchedule taint from nodes |
| 51 | for MNODE in \$(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do |
| 52 | kubectl taint node "\$MNODE" node-role.kubernetes.io/master:NoSchedule- |
| 53 | done |
| 54 | |
| 55 | mkdir -p $HOME/.volt |
| 56 | voltctl -s localhost:55555 config > $HOME/.volt/config |
| 57 | |
| 58 | mkdir -p $HOME/.kube |
| 59 | kind get kubeconfig --name ${cfg.name} > $HOME/.kube/config |
| 60 | |
| 61 | # add helm repositories |
| 62 | helm repo add onf https://charts.opencord.org |
| 63 | helm repo update |
| 64 | |
| 65 | # download kail |
| 66 | bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin" |
| 67 | """ |
| 68 | } |