Vasyl Saienko | 775c1da | 2023-07-13 11:34:25 +0000 | [diff] [blame^] | 1 | EXAMPLES_DIR=$(cd $(dirname "$0")/.. && pwd) |
| 2 | WORKDIR=$(cd $(dirname "$0") && pwd) |
| 3 | |
| 4 | TMP_DIR=$(cd $(dirname "$0")/../../.workdir/ && pwd) |
| 5 | source ${EXAMPLES_DIR}/lib.sh |
| 6 | |
| 7 | command=$1 |
| 8 | |
| 9 | function run { |
| 10 | echo "Downloading cirros" |
| 11 | if [[ ! -f ${TMP_DIR}/cirros-0.6.2-x86_64-disk.img ]]; then |
| 12 | wget https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img -O ${TMP_DIR}/cirros-0.6.2-x86_64-disk.img |
| 13 | fi |
| 14 | |
| 15 | echo "Uploading cirros to PVC." |
| 16 | UPLOADPROXY_URL=https://$(kubectl get nodes -o wide| tail -1 | awk '{print $6}'):31119 |
| 17 | virtctl image-upload pvc cirros-cdi-pvc --size 5G --image-path=${TMP_DIR}/cirros-0.6.2-x86_64-disk.img --insecure --uploadproxy-url ${UPLOADPROXY_URL} |
| 18 | |
| 19 | kubectl get pvc |
| 20 | kubectl get pods |
| 21 | |
| 22 | echo "Creating VM" |
| 23 | kubectl apply -f cirros.yaml |
| 24 | |
| 25 | echo "Starting VM" |
| 26 | virtctl start cirros-cdi-pvc |
| 27 | |
| 28 | echo "Waiting VM is Running." |
| 29 | wait_vm_state cirros-cdi-pvc Running |
| 30 | } |
| 31 | |
| 32 | function cleanup { |
| 33 | kubectl delete -f cirros.yaml |
| 34 | kubectl delete datavolume cirros-cdi-pvc |
| 35 | kubectl delete pvc cirros-cdi-pvc |
| 36 | } |
| 37 | |
| 38 | pushd $WORKDIR |
| 39 | $command |
| 40 | popd |