|
2 | 2 |
|
3 | 3 | @test "Create a VM Disk" { |
4 | 4 | name='test' |
5 | | - kubectl -n tenant-test delete vminstances.apps.cozystack.io $name --ignore-not-found --timeout=2m || true |
6 | | - kubectl -n tenant-test delete vmdisks.apps.cozystack.io $name --ignore-not-found --timeout=2m || true |
| 5 | + # Delete any leftover from a previous run and BLOCK until removal completes. |
| 6 | + # `kubectl apply` on a resource still in finalizer-drain silently no-ops |
| 7 | + # ("Detected changes to resource ... which is currently being deleted"), |
| 8 | + # which then races a NotFound on the downstream HR wait. The previous |
| 9 | + # `|| true` swallowed timeout errors here and let the test continue with |
| 10 | + # the old VMDisk still draining. Bumped timeout to 3m and removed `|| true` |
| 11 | + # so a true delete failure surfaces immediately. |
| 12 | + kubectl -n tenant-test delete vminstances.apps.cozystack.io $name --ignore-not-found --timeout=3m |
| 13 | + kubectl -n tenant-test delete vmdisks.apps.cozystack.io $name --ignore-not-found --timeout=3m |
7 | 14 | kubectl apply -f - <<EOF |
8 | 15 | apiVersion: apps.cozystack.io/v1alpha1 |
9 | 16 | kind: VMDisk |
|
18 | 25 | storage: 5Gi |
19 | 26 | storageClass: replicated |
20 | 27 | EOF |
21 | | - sleep 5 |
| 28 | + # Wait for the operator to materialise the HelmRelease before kubectl wait |
| 29 | + # kicks in (kubectl wait errors immediately if the object does not exist yet). |
| 30 | + timeout 60 sh -ec "until kubectl -n tenant-test get hr vm-disk-$name >/dev/null 2>&1; do sleep 2; done" |
22 | 31 | kubectl -n tenant-test wait hr vm-disk-$name --timeout=5s --for=condition=ready |
23 | 32 | kubectl -n tenant-test wait dv vm-disk-$name --timeout=250s --for=condition=ready |
24 | 33 | kubectl -n tenant-test wait pvc vm-disk-$name --timeout=200s --for=jsonpath='{.status.phase}'=Bound |
|
27 | 36 | @test "Create a VM Instance" { |
28 | 37 | diskName='test' |
29 | 38 | name='test' |
30 | | - kubectl -n tenant-test delete vminstances.apps.cozystack.io $name --ignore-not-found --timeout=2m || true |
| 39 | + # Same delete-finalizer-drain race as in "Create a VM Disk" above — |
| 40 | + # block until removal completes, surface timeouts loudly. |
| 41 | + kubectl -n tenant-test delete vminstances.apps.cozystack.io $name --ignore-not-found --timeout=3m |
31 | 42 | kubectl apply -f - <<EOF |
32 | 43 | apiVersion: apps.cozystack.io/v1alpha1 |
33 | 44 | kind: VMInstance |
@@ -59,10 +70,16 @@ spec: |
59 | 70 | - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPht0dPk5qQ+54g1hSX7A6AUxXJW5T6n/3d7Ga2F8gTF test@test |
60 | 71 | cloudInitSeed: "" |
61 | 72 | EOF |
62 | | - sleep 5 |
63 | | - timeout 20 sh -ec "until kubectl -n tenant-test get vmi vm-instance-$name -o jsonpath='{.status.interfaces[0].ipAddress}' | grep -q '[0-9]'; do sleep 5; done" |
| 73 | + # Wait for the operator to materialise the HelmRelease before downstream |
| 74 | + # waits proceed (kubectl wait errors immediately if the HR does not exist). |
| 75 | + timeout 60 sh -ec "until kubectl -n tenant-test get hr vm-instance-$name >/dev/null 2>&1; do sleep 2; done" |
| 76 | + # Nested KubeVirt VM startup (virt-launcher + libvirt + cloud-init DHCP) |
| 77 | + # routinely takes 30-60s under runner load; the previous 20s was unrealistic |
| 78 | + # and produced flakes. 120s is a comfortable upper bound for nested virt. |
| 79 | + timeout 120 sh -ec "until kubectl -n tenant-test get vmi vm-instance-$name -o jsonpath='{.status.interfaces[0].ipAddress}' | grep -q '[0-9]'; do sleep 2; done" |
64 | 80 | kubectl -n tenant-test wait hr vm-instance-$name --timeout=5s --for=condition=ready |
65 | | - kubectl -n tenant-test wait vm vm-instance-$name --timeout=20s --for=condition=ready |
66 | | - kubectl -n tenant-test delete vminstances.apps.cozystack.io $name |
67 | | - kubectl -n tenant-test delete vmdisks.apps.cozystack.io $diskName |
| 81 | + # VM ready follows IP assignment closely; 60s gives buffer for the qemu-guest-agent. |
| 82 | + kubectl -n tenant-test wait vm vm-instance-$name --timeout=60s --for=condition=ready |
| 83 | + kubectl -n tenant-test delete vminstances.apps.cozystack.io $name --timeout=3m |
| 84 | + kubectl -n tenant-test delete vmdisks.apps.cozystack.io $diskName --timeout=3m |
68 | 85 | } |
0 commit comments