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 | source ${EXAMPLES_DIR}/lib.sh |
| 4 | |
| 5 | command=$1 |
| 6 | |
| 7 | function run { |
| 8 | echo "Creating PVC" |
| 9 | kubectl apply -f pvc.yaml |
| 10 | |
| 11 | echo "Creating VM" |
| 12 | kubectl apply -f cirros.yaml |
| 13 | |
| 14 | echo "Waiting VM is Running." |
| 15 | wait_vm_state cirros-clone Running |
| 16 | |
| 17 | echo "Login to VM and create some data on the volume. For example run:" |
| 18 | echo "sudo su" |
| 19 | echo "mkfs.ext4 /dev/sda" |
| 20 | echo "mkdir /mnt/vol01" |
| 21 | echo "mount -t ext4 /dev/sda /mnt/vol01" |
| 22 | echo "date > /mnt/vol01/here" |
| 23 | echo "sync" |
| 24 | |
| 25 | read -p "Press any key to create clone" -n 1 -r |
| 26 | echo "Creating clone" |
| 27 | |
| 28 | kubectl apply -f clone.yaml |
| 29 | |
| 30 | echo "Waiting clone is created" |
| 31 | kubectl wait vmclone cirros-clone --for condition=Ready |
| 32 | |
| 33 | kubectl get pvc |
| 34 | kubectl get vm |
| 35 | } |
| 36 | |
| 37 | function cleanup { |
| 38 | kubectl delete -f cirros.yaml |
| 39 | kubectl delete -f pvc.yaml |
| 40 | kubectl delete -f clone.yaml |
| 41 | |
| 42 | kubectl delete vm cirros-clone-target |
| 43 | kubectl delete vmsnapshot cirros-snapshot |
| 44 | } |
| 45 | |
| 46 | pushd $WORKDIR |
| 47 | $command |
| 48 | popd |