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?) |
Andrea Campanella | 0e540ba | 2021-10-01 11:16:03 +0200 | [diff] [blame] | 52 | curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 53 | chmod +x ./kind |
| 54 | mv ./kind $WORKSPACE/bin/kind |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 55 | """ |
| 56 | // install voltctl |
| 57 | installVoltctl("${cfg.branch}") |
| 58 | sh """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 59 | # start the kind cluster |
| 60 | kind create cluster --name ${cfg.name} --config kind.cfg |
| 61 | |
| 62 | # remove NoSchedule taint from nodes |
| 63 | for MNODE in \$(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do |
| 64 | kubectl taint node "\$MNODE" node-role.kubernetes.io/master:NoSchedule- |
| 65 | done |
| 66 | |
| 67 | mkdir -p $HOME/.volt |
| 68 | voltctl -s localhost:55555 config > $HOME/.volt/config |
| 69 | |
| 70 | mkdir -p $HOME/.kube |
| 71 | kind get kubeconfig --name ${cfg.name} > $HOME/.kube/config |
| 72 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 73 | # download kail |
| 74 | bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin" |
| 75 | """ |
| 76 | } |