blob: d329de2dcabff952aaaf89a3bc5fd809c1ee8759 [file] [log] [blame]
Matteo Scandolo42f6e572021-01-25 15:11:34 -08001// sets up a kubernetes cluster (using kind)
2
3def 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 Windlass6f854a12021-07-12 13:20:21 +00006 branch: "master",
Matteo Scandolo42f6e572021-01-25 15:11:34 -08007 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 = """
21kind: Cluster
22apiVersion: kind.x-k8s.io/v1alpha4
23nodes:
Matteo Scandolo9b644ba2021-04-19 11:21:07 -070024- role: worker
25- role: worker
Matteo Scandolo42f6e572021-01-25 15:11:34 -080026- role: control-plane
Matteo Scandolo9b644ba2021-04-19 11:21:07 -070027 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 Scandolo42f6e572021-01-25 15:11:34 -080044 """
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 Campanella0e540ba2021-10-01 11:16:03 +020052 curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64
Matteo Scandolo42f6e572021-01-25 15:11:34 -080053 chmod +x ./kind
54 mv ./kind $WORKSPACE/bin/kind
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070055 """
56 // install voltctl
57 installVoltctl("${cfg.branch}")
58 sh """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080059 # 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 Scandolo42f6e572021-01-25 15:11:34 -080073 # download kail
74 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin"
75 """
76}