github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/hack/run-e2e-test-kind.sh (about) 1 #!/usr/bin/env bash 2 set -eo pipefail 3 here="$(dirname "$(readlink --canonicalize "${BASH_SOURCE[0]}")")" 4 root="$(readlink --canonicalize "$here/..")" 5 export SRIOV_NETWORK_OPERATOR_IMAGE="${SRIOV_NETWORK_OPERATOR_IMAGE:-sriov-network-operator:e2e-test}" 6 export SRIOV_NETWORK_CONFIG_DAEMON_IMAGE="${SRIOV_NETWORK_CONFIG_DAEMON_IMAGE:-origin-sriov-network-config-daemon:e2e-test}" 7 export KUBECONFIG="${KUBECONFIG:-${HOME}/.kube/config}" 8 INTERFACES_SWITCHER="${INTERFACES_SWITCHER:-"test-suite"}" 9 SUPPORTED_INTERFACE_SWTICHER_MODES=("test-suite", "system-service") 10 RETRY_MAX=10 11 INTERVAL=10 12 TIMEOUT=300 13 MULTUS_CNI_DS="https://raw.githubusercontent.com/intel/multus-cni/master/deployments/multus-daemonset.yml" 14 15 while test $# -gt 0; do 16 case "$1" in 17 --device-netns-switcher) 18 INTERFACES_SWITCHER="$2" 19 if [[ ! "${SUPPORTED_INTERFACE_SWTICHER_MODES[@]}" =~ "${INTERFACES_SWITCHER}" ]]; then 20 echo "Error: unsupported interface switching mode: ${INTERFACES_SWITCHER}!" 21 echo "Supported modes are: ${SUPPORTED_INTERFACE_SWTICHER_MODES[@]}" 22 exit 1 23 fi 24 shift 25 shift 26 ;; 27 28 --pf-pci-address) 29 test_pf_pci_addr="$2" 30 shift 31 shift 32 ;; 33 34 *) 35 if [[ -z "$test_pf_pci_addr" ]];then 36 test_pf_pci_addr=$1 37 fi 38 shift 39 ;; 40 esac 41 done 42 43 check_requirements() { 44 for cmd in docker kind kubectl ip; do 45 if ! command -v "$cmd" &> /dev/null; then 46 echo "$cmd is not available" 47 exit 1 48 fi 49 done 50 51 if [ "$test_pf_pci_addr" == "" ]; then 52 echo "specify a physical function PCI address as an argument" 53 echo "e.g. $0 0000:01:00.0" 54 exit 1 55 fi 56 return 0 57 } 58 59 retry() { 60 local status=0 61 local retries=${RETRY_MAX:=5} 62 local delay=${INTERVAL:=5} 63 local to=${TIMEOUT:=20} 64 cmd="$*" 65 66 while [ $retries -gt 0 ] 67 do 68 status=0 69 timeout $to bash -c "echo $cmd && $cmd" || status=$? 70 if [ $status -eq 0 ]; then 71 break; 72 fi 73 echo "Exit code: '$status'. Sleeping '$delay' seconds before retrying" 74 sleep $delay 75 (( retries-- )) 76 done 77 return $status 78 } 79 80 echo "## checking requirements" 81 check_requirements 82 echo "## delete any existing cluster, deploy control & data plane cluster with KinD" 83 retry kind delete cluster && cat <<EOF | kind create cluster --kubeconfig=${KUBECONFIG} --config=- 84 kind: Cluster 85 apiVersion: kind.x-k8s.io/v1alpha4 86 nodes: 87 - role: control-plane 88 - role: worker 89 EOF 90 sudo chmod 644 ${KUBECONFIG} 91 echo "## build operator image" 92 retry docker build -t "${SRIOV_NETWORK_OPERATOR_IMAGE}" -f "${root}/Dockerfile" "${root}" 93 echo "## load operator image into KinD" 94 kind load docker-image "${SRIOV_NETWORK_OPERATOR_IMAGE}" 95 echo "## build daemon image" 96 retry docker build -t "${SRIOV_NETWORK_CONFIG_DAEMON_IMAGE}" -f "${root}/Dockerfile.sriov-network-config-daemon" "${root}" 97 echo "## load daemon image into KinD" 98 kind load docker-image "${SRIOV_NETWORK_CONFIG_DAEMON_IMAGE}" 99 echo "## export kube config for utilising locally" 100 kind export kubeconfig 101 echo "## wait for coredns" 102 retry kubectl -n kube-system wait --for=condition=available deploy/coredns --timeout=${TIMEOUT}s 103 echo "## install multus" 104 retry kubectl create -f "$MULTUS_CNI_DS" 105 echo "## wait for multus" 106 retry kubectl -n kube-system wait --for=condition=ready -l name=multus pod --timeout=${TIMEOUT}s 107 echo "## find KinD container" 108 kind_container="$(docker ps -q --filter 'name=kind-worker')" 109 echo "## validate KinD cluster formed" 110 [ "$kind_container" == "" ] && echo "could not find a KinD container 'kind-worker'" && exit 5 111 echo "## make KinD's sysfs writable (required to create VFs)" 112 docker exec "$kind_container" mount -o remount,rw /sys 113 echo "## label KinD's control-plane-node as sriov capable" 114 kubectl label node kind-worker feature.node.kubernetes.io/network-sriov.capable=true --overwrite 115 echo "## label KinD worker as worker" 116 kubectl label node kind-worker node-role.kubernetes.io/worker= --overwrite 117 if [[ "${INTERFACES_SWITCHER}" == "system-service" ]];then 118 pf="$(ls /sys/bus/pci/devices/${test_pf_pci_addr}/net)" 119 mkdir -p /etc/vf-switcher 120 cat <<EOF > /etc/vf-switcher/vf-switcher.yaml 121 [ 122 { 123 "netns": "${kind_container}", 124 "pfs": [ 125 "${pf}" 126 ] 127 } 128 ] 129 EOF 130 sudo systemctl restart vf-switcher.service 131 else 132 echo "## retrieving netns path from container" 133 netns_path="$(sudo docker inspect --format '{{ .NetworkSettings.SandboxKey }}' "${kind_container}")" 134 echo "## exporting test device '${test_pf_pci_addr}' and test netns path '${netns_path}'" 135 export TEST_PCI_DEVICE="${test_pf_pci_addr}" 136 export TEST_NETNS_PATH="${netns_path}" 137 fi 138 echo "## disabling webhooks" 139 export ADMISSION_CONTROLLERS_ENABLED=false 140 echo "## deploying SRIOV Network Operator" 141 make --directory "${root}" deploy-setup-k8s 142 echo "## wait for sriov-network-config-daemon to be ready" 143 retry kubectl -n sriov-network-operator wait --for=condition=ready -l app=sriov-network-config-daemon pod --timeout=${TIMEOUT}s 144 echo "## Executing E2E tests" 145 make --directory "${root}" test-e2e-k8s