blob: 0742a56e8b4ae825255a0e316abe631bc6f70be7 [file] [log] [blame]
Vasyl Saienko775c1da2023-07-13 11:34:25 +00001EXAMPLES_DIR=$(cd $(dirname "$0")/.. && pwd)
2WORKDIR=$(cd $(dirname "$0") && pwd)
3source ${EXAMPLES_DIR}/lib.sh
4
5command=$1
6
7function 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-snapshot 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 snapshot" -n 1 -r
26 echo "Creating snapshot"
27
28 kubectl apply -f snapshot.yaml
29 wait_vmsnapshot_state cirros-snapshot Succeeded
30
31 kubectl get vmsnapshot
32 kubectl get volumesnapshotcontents
33
34 echo "Login to VM and create some more data on the volume. For example run:"
35 echo "sudo su"
36 echo "mkdir /mnt/vol01"
37 echo "mount -t ext4 /dev/sda /mnt/vol01"
38 echo "date > /mnt/vol01/there"
39 echo "sync"
40
41 read -p "Press any key to stop VM" -n 1 -r
42 virtctl stop cirros-snapshot
43 wait_vm_state cirros-snapshot Stopped
44
45 read -p "Press any key to restore VM snapshot" -n 1 -r
46 kubectl apply -f restore.yaml
47
48 wait_vmrestore_completed cirros-snapshot
49
50
51 echo "Starting VM"
52 virtctl start cirros-snapshot
53 wait_vm_state cirros-snapshot Running
54
55 echo "Login to VM and check data on the volume. For example run:"
56 echo "sudo su"
57 echo "mkdir /mnt/vol01"
58 echo "mount -t ext4 /dev/sda /mnt/vol01"
59 echo "ls -lah /mnt/vol01/"
60}
61
62
63function cleanup {
64 kubectlt delete -f snapshot.yaml
65 kubectl delete -f restore.yaml
66 kubectl delete -f pvc.yaml
67 kubectl delete -f cirros.yaml
68}
69
70pushd $WORKDIR
71$command
72popd