blob: 5ef69f9ce1e7d93e618353a70f1d8cdb96a07e5e [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?)
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 Windlass6f854a12021-07-12 13:20:21 +000062 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 Windlassabd342c2021-03-25 12:20:43 +053067 curl -Lo $WORKSPACE/bin/voltctl https://github.com/opencord/voltctl/releases/download/v\$VC_VERSION/voltctl-\$VC_VERSION-\$HOSTOS-\$HOSTARCH
Matteo Scandolo29597f02021-02-12 10:53:57 -080068 chmod +x $WORKSPACE/bin/voltctl
Matteo Scandolo42f6e572021-01-25 15:11:34 -080069
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 Scandolo42f6e572021-01-25 15:11:34 -080084 # download kail
85 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin"
86 """
87}