CSIT-1065 High failure rate with K8s/Ligato orchestration
[csit.git] / resources / libraries / bash / k8s_setup.sh
1 #!/bin/bash
2 # Copyright (c) 2018 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 set -xo pipefail
16
17 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18
19 # Include
20 source ${SCRIPT_DIR}/config/defaults
21 source ${SCRIPT_DIR}/shell/dpdk_utils.sh
22 source ${SCRIPT_DIR}/shell/k8s_utils.sh
23
24 # Read configuration
25 while read line
26 do
27     if echo $line | grep -F = &>/dev/null
28     then
29         varname=$(echo "$line" | cut -d '=' -f 1)
30         cfg[$varname]=$(echo "$line" | cut -d '=' -f 2-)
31     fi
32 done < ${SCRIPT_DIR}/config/config
33
34 trap "k8s_utils.destroy" ERR
35
36 case "$1" in
37     prepare)
38         # Revert any changes made to this host by 'kubeadm init'
39         k8s_utils.destroy
40         # Sets up the Kubernetes master
41         k8s_utils.prepare
42         ;;
43     deploy_calico)
44         # Revert any changes made to this host by 'kubeadm init'
45         k8s_utils.destroy
46         # Load kernel modules uio/uio_pci_generic
47         dpdk_utils.load_modules
48         # Sets up the Kubernetes master
49         k8s_utils.prepare "--pod-network-cidr=192.168.0.0/16"
50         # Apply resources
51         k8s_utils.calico_deploy ${cfg[K8S_CALICO]}
52         # Dump Kubernetes objects ...
53         k8s_utils.dump_all
54         ;;
55     affinity_non_vpp)
56         # Set affinity for all non VPP docker containers to CPU 0
57         k8s_utils.affinity_non_vpp
58         ;;
59     destroy)
60         # Revert any changes made to this host by 'kubeadm init'
61         k8s_utils.destroy
62         ;;
63     *)
64         echo "usage: $0 function"
65         echo "function:"
66         echo "    prepare"
67         echo "    deploy_calico"
68         echo "    affinity_non_vpp"
69         echo "    destroy"
70         exit 1
71 esac
72 shift
73
74 echo Kubernetes setup finished