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