blob: 36bd51047d12c46c1be3f7bb737b7d1c718f23db [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:
Matteo Scandolo9b644ba2021-04-19 11:21:07 -070023- role: worker
24- role: worker
Matteo Scandolo42f6e572021-01-25 15:11:34 -080025- role: control-plane
Matteo Scandolo9b644ba2021-04-19 11:21:07 -070026 kubeadmConfigPatches:
27 - |
28 kind: InitConfiguration
29 nodeRegistration:
30 kubeletExtraArgs:
31 node-labels: "ingress-ready=true"
32 extraPortMappings:
33 - containerPort: 80
34 hostPort: 80
35 protocol: TCP
36 - containerPort: 443
37 hostPort: 443
38 protocol: TCP
39 - containerPort: 30115
40 hostPort: 30115
41 - containerPort: 30120
42 hostPort: 30120
Matteo Scandolo42f6e572021-01-25 15:11:34 -080043 """
44 writeFile(file: 'kind.cfg', text: data)
45
46 // TODO skip cluster creation if cluster is already there
47 sh """
48 mkdir -p $WORKSPACE/bin
49
50 # download kind (should we add it to the base image?)
51 curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64
52 chmod +x ./kind
53 mv ./kind $WORKSPACE/bin/kind
54
55 # install voltctl
56 HOSTOS="\$(uname -s | tr "[:upper:]" "[:lower:"])"
57 HOSTARCH="\$(uname -m | tr "[:upper:]" "[:lower:"])"
58 if [ "\$HOSTARCH" == "x86_64" ]; then
59 HOSTARCH="amd64"
60 fi
Hardik Windlassabd342c2021-03-25 12:20:43 +053061 VC_VERSION="\$(curl --fail -sSL https://api.github.com/repos/opencord/voltctl/releases/latest | jq -r .tag_name | sed -e 's/^v//g')"
62 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 -080063 chmod +x $WORKSPACE/bin/voltctl
Matteo Scandolo42f6e572021-01-25 15:11:34 -080064
65 # start the kind cluster
66 kind create cluster --name ${cfg.name} --config kind.cfg
67
68 # remove NoSchedule taint from nodes
69 for MNODE in \$(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do
70 kubectl taint node "\$MNODE" node-role.kubernetes.io/master:NoSchedule-
71 done
72
73 mkdir -p $HOME/.volt
74 voltctl -s localhost:55555 config > $HOME/.volt/config
75
76 mkdir -p $HOME/.kube
77 kind get kubeconfig --name ${cfg.name} > $HOME/.kube/config
78
79 # add helm repositories
80 helm repo add onf https://charts.opencord.org
81 helm repo update
82
83 # download kail
84 bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin"
85 """
86}