Add Multus with Calico and SRIOV CNI support
[iec.git] / src / foundation / scripts / cni / multus / multus-sriov-calico / install-k8s-v1.16.sh
1 #!/bin/bash -ex
2 # shellcheck disable=SC2016,SC2046
3
4 function wait_for {
5   # Execute in a subshell to prevent local variable override during recursion
6   (
7     local total_attempts=$1; shift
8     local cmdstr=$*
9     local sleep_time=2
10     echo -e "\n[wait_for] Waiting for cmd to return success: ${cmdstr}"
11     # shellcheck disable=SC2034
12     for attempt in $(seq "${total_attempts}"); do
13       echo "[wait_for] Attempt ${attempt}/${total_attempts%.*} for: ${cmdstr}"
14       # shellcheck disable=SC2015
15       eval "${cmdstr}" && echo "[wait_for] OK: ${cmdstr}" && return 0 || true
16       sleep "${sleep_time}"
17     done
18     echo "[wait_for] ERROR: Failed after max attempts: ${cmdstr}"
19     return 1
20   )
21 }
22
23 kubectl create -f configMap.yaml
24 wait_for 5 'test $(kubectl get configmap -n kube-system | grep sriovdp-config -c ) -eq 1'
25
26 kubectl create -f multus-sriov-calico-daemonsets-k8s-v1.16.yaml
27 wait_for 100 'test $(kubectl get pods -n kube-system | grep -e "kube-multus-ds" | grep "Running" -c) -ge 1'
28 wait_for 20 'test $(kubectl get pods -n kube-system | grep -e "kube-sriov-cni" | grep "Running" -c) -ge 1'
29 wait_for 20 'test $(kubectl get pods -n kube-system | grep -e "kube-sriov-device-plugin" | grep "Running" -c) -ge 1'
30
31 kubectl create -f calico-daemonset-k8s-v1.16.yaml
32 wait_for 20 'test $(kubectl get pods -n kube-system | grep -e "calico-kube-controllers" | grep "Running" -c) -ge 1'
33 wait_for 20 'test $(kubectl get pods -n kube-system | grep -e "calico-node" | grep "Running" -c) -ge 1'
34
35 kubectl create -f sriov-crd.yaml
36 wait_for 5 'test $(kubectl get crd | grep -e "network-attachment-definitions" -c) -ge 1'
37
38 sleep 2
39 kubectl get node $(hostname) -o json | jq '.status.allocatable' || true
40 kubectl get pods --all-namespaces