blob: 48a0bea6190b48d1e5a8b22d3be0ec891bed7183 [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 = [
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 = """
20kind: Cluster
21apiVersion: kind.x-k8s.io/v1alpha4
22nodes:
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
Hardik Windlassabd342c2021-03-25 12:20:43 +053044 VC_VERSION="\$(curl --fail -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')"
45 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 -080046 chmod +x $WORKSPACE/bin/voltctl
Matteo Scandolo42f6e572021-01-25 15:11:34 -080047
48 # start the kind cluster
49 kind create cluster --name ${cfg.name} --config kind.cfg
50
51 # remove NoSchedule taint from nodes
52 for MNODE in \$(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do
53 kubectl taint node "\$MNODE" node-role.kubernetes.io/master:NoSchedule-
54 done
55
56 mkdir -p $HOME/.volt
57 voltctl -s localhost:55555 config > $HOME/.volt/config
58
59 mkdir -p $HOME/.kube
60 kind get kubeconfig --name ${cfg.name} > $HOME/.kube/config
61
62 # add helm repositories
63 helm repo add onf https://charts.opencord.org
64 helm repo update
65
66 # download kail
67 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin"
68 """
69}