-
Notifications
You must be signed in to change notification settings - Fork 10
/
kubevirt.sh
executable file
·94 lines (84 loc) · 2.79 KB
/
kubevirt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o errexit
set -o nounset
set -o pipefail
# shellcheck source=tests/_functions.sh
source _functions.sh
# shellcheck source=tests/_assertions.sh
source _assertions.sh
function cleanup {
attempt_counter=0
max_attempts=5
kubectl delete vm testvm --ignore-not-found=true
while kubectl get pods -l kubevirt.io=virt-launcher | grep -q "virt-launcher"; do
if [ ${attempt_counter} -eq ${max_attempts} ]; then
error "Max attempts reached"
fi
attempt_counter=$((attempt_counter + 1))
sleep $((attempt_counter * 10))
done
}
trap cleanup EXIT
# Test
info "===== Test started ====="
# editorconfig-checker-disable
cat <<EOL | kubectl apply -f -
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
name: testvm
spec:
running: false
template:
metadata:
labels:
kubevirt.io/size: tiny # tiny(1 core, 1 Gi memory), small (1 core, 2 Gi memory), medium (1 core, 4 Gi memory), large (2 cores, 8 Gi memory).
kubevirt.io/domain: testvm
spec:
domain:
devices:
disks:
- name: containerdisk
disk:
bus: virtio
- name: cloudinitdisk
disk:
bus: virtio
interfaces:
- name: default
bridge: {}
resources:
requests:
memory: 64M
networks:
- name: default
pod: {}
volumes:
- name: containerdisk
containerDisk:
image: kubevirt/cirros-registry-disk-demo
- name: cloudinitdisk
cloudInitNoCloud:
userDataBase64: SGkuXG4=
EOL
# editorconfig-checker-enable
kubectl get vms
[ -d "${KREW_ROOT:-$HOME/.krew}/bin" ] && export PATH="$PATH:${KREW_ROOT:-$HOME/.krew}/bin"
! kubectl plugin list | grep -q virt && kubectl krew install virt
kubectl virt start testvm
kubectl wait --for=condition=ready vmis testvm --timeout=5m >/dev/null
vm_pod=$(kubectl get pods -o jsonpath='{.items[0].metadata.name}' | grep virt-launcher-testvm)
info "$vm_pod details:"
kubectl logs "$vm_pod" -c compute | jq -R "fromjson? | .msg"
info "$vm_pod assertions:"
assert_non_empty "$(kubectl logs "$vm_pod" -c compute | grep 'Successfully connected to domain notify socket at')" "testvm unsuccessfully created"
#kubectl virt console testvm
info "===== Test completed ====="