Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 3 | // sets up a kubernetes cluster (using kind) |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 4 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 5 | |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 6 | // ----------------------------------------------------------------------- |
| 7 | // ----------------------------------------------------------------------- |
| 8 | def getIam(String func) |
| 9 | { |
| 10 | // Cannot rely on a stack trace due to jenkins manipulation |
| 11 | String src = 'vars/createKubernetesCluster.groovy' |
| 12 | String iam = [src, func].join('::') |
| 13 | return iam |
| 14 | } |
| 15 | |
| 16 | // ----------------------------------------------------------------------- |
| 17 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 18 | def call(Map config) { |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 19 | |
| 20 | String iam = getIam('main') |
| 21 | println("** ${iam}: ENTER") |
| 22 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 23 | // note that I can't define this outside the function as there's no global scope in Groovy |
| 24 | def defaultConfig = [ |
Hardik Windlass | 6f854a1 | 2021-07-12 13:20:21 +0000 | [diff] [blame] | 25 | branch: "master", |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 26 | nodes: 1, |
| 27 | name: "kind-ci" |
| 28 | ] |
| 29 | |
| 30 | if (!config) { |
| 31 | config = [:] |
| 32 | } |
| 33 | |
| 34 | def cfg = defaultConfig + config |
| 35 | |
| 36 | println "Deploying Kind cluster with the following parameters: ${cfg}." |
| 37 | |
| 38 | // TODO support different configs |
| 39 | def data = """ |
| 40 | kind: Cluster |
| 41 | apiVersion: kind.x-k8s.io/v1alpha4 |
| 42 | nodes: |
Matteo Scandolo | 9b644ba | 2021-04-19 11:21:07 -0700 | [diff] [blame] | 43 | - role: worker |
| 44 | - role: worker |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 45 | - role: control-plane |
Matteo Scandolo | 9b644ba | 2021-04-19 11:21:07 -0700 | [diff] [blame] | 46 | kubeadmConfigPatches: |
| 47 | - | |
| 48 | kind: InitConfiguration |
| 49 | nodeRegistration: |
| 50 | kubeletExtraArgs: |
| 51 | node-labels: "ingress-ready=true" |
| 52 | extraPortMappings: |
| 53 | - containerPort: 80 |
| 54 | hostPort: 80 |
| 55 | protocol: TCP |
| 56 | - containerPort: 443 |
| 57 | hostPort: 443 |
| 58 | protocol: TCP |
| 59 | - containerPort: 30115 |
| 60 | hostPort: 30115 |
| 61 | - containerPort: 30120 |
| 62 | hostPort: 30120 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 63 | """ |
| 64 | writeFile(file: 'kind.cfg', text: data) |
| 65 | |
| 66 | // TODO skip cluster creation if cluster is already there |
| 67 | sh """ |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 68 | mkdir -p "$WORKSPACE/bin" |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 69 | |
| 70 | # download kind (should we add it to the base image?) |
Andrea Campanella | 0e540ba | 2021-10-01 11:16:03 +0200 | [diff] [blame] | 71 | curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 72 | chmod +x ./kind |
| 73 | mv ./kind $WORKSPACE/bin/kind |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 74 | """ |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 75 | |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 76 | // install voltctl |
| 77 | installVoltctl("${cfg.branch}") |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 78 | |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 79 | sh """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 80 | # start the kind cluster |
| 81 | kind create cluster --name ${cfg.name} --config kind.cfg |
| 82 | |
| 83 | # remove NoSchedule taint from nodes |
| 84 | for MNODE in \$(kubectl get node --selector='node-role.kubernetes.io/master' -o json | jq -r '.items[].metadata.name'); do |
| 85 | kubectl taint node "\$MNODE" node-role.kubernetes.io/master:NoSchedule- |
| 86 | done |
| 87 | |
| 88 | mkdir -p $HOME/.volt |
| 89 | voltctl -s localhost:55555 config > $HOME/.volt/config |
| 90 | |
| 91 | mkdir -p $HOME/.kube |
| 92 | kind get kubeconfig --name ${cfg.name} > $HOME/.kube/config |
| 93 | |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 94 | make -C "$WORKSPACE/voltha-system-tests" KAIL_PATH="$WORKSPACE/bin" kail || true |
| 95 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 96 | # download kail |
| 97 | bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$WORKSPACE/bin" |
| 98 | """ |
Joey Armstrong | 7496127 | 2023-01-12 13:35:54 -0500 | [diff] [blame^] | 99 | |
| 100 | println("** ${iam}: LEAVE") |
| 101 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 102 | } |