blob: fccbaed5767003d31c8209c636e928740fd2a221 [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
44 curl -Lo ./voltctl https://github.com/opencord/voltctl/releases/download/v1.3.1/voltctl-1.3.1-\$HOSTOS-\$HOSTARCH
45 chmod +x ./voltctl
46 mv ./voltctl $WORKSPACE/bin/
47
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}