-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add virt capacity benchmark test (#180)
Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
- Loading branch information
Showing
13 changed files
with
744 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env bash | ||
COMMAND=$1 | ||
LABEL_KEY=$2 | ||
LABEL_VALUE=$3 | ||
NAMESPACE=$4 | ||
IDENTITY_FILE=$5 | ||
REMOTE_USER=$6 | ||
EXPECTED_ROOT_SIZE=$7 | ||
EXPECTED_DATA_SIZE=$8 | ||
|
||
# Wait up to ~60 minutes | ||
MAX_RETRIES=130 | ||
# In the first reties use a shorter sleep | ||
MAX_SHORT_WAITS=12 | ||
SHORT_WAIT=5 | ||
LONG_WAIT=30 | ||
|
||
if virtctl ssh --help | grep -qc "\--local-ssh " ; then | ||
LOCAL_SSH="--local-ssh" | ||
else | ||
LOCAL_SSH="" | ||
fi | ||
|
||
get_vms() { | ||
local namespace=$1 | ||
local label_key=$2 | ||
local label_value=$3 | ||
|
||
local vms | ||
vms=$(kubectl get vm -n "${namespace}" -l "${label_key}"="${label_value}" -o json | jq .items | jq -r '.[] | .metadata.name') | ||
local ret=$? | ||
if [ $ret -ne 0 ]; then | ||
echo "Failed to get VM list" | ||
exit 1 | ||
fi | ||
echo "${vms}" | ||
} | ||
|
||
remote_command() { | ||
local namespace=$1 | ||
local identity_file=$2 | ||
local remote_user=$3 | ||
local vm_name=$4 | ||
local command=$5 | ||
|
||
local output | ||
output=$(virtctl ssh ${LOCAL_SSH} --local-ssh-opts="-o StrictHostKeyChecking=no" --local-ssh-opts="-o UserKnownHostsFile=/dev/null" -n "${namespace}" -i "${identity_file}" -c "${command}" --username "${remote_user}" "${vm_name}" 2>/dev/null) | ||
local ret=$? | ||
if [ $ret -ne 0 ]; then | ||
return 1 | ||
fi | ||
echo "${output}" | ||
} | ||
|
||
check_vm_running() { | ||
local vm=$1 | ||
remote_command "${NAMESPACE}" "${IDENTITY_FILE}" "${REMOTE_USER}" "${vm}" "ls" | ||
return $? | ||
} | ||
|
||
check_resize() { | ||
local vm=$1 | ||
|
||
local blk_devices | ||
blk_devices=$(remote_command "${NAMESPACE}" "${IDENTITY_FILE}" "${REMOTE_USER}" "${vm}" "lsblk --json -v --output=NAME,SIZE") | ||
local ret=$? | ||
if [ $ret -ne 0 ]; then | ||
return $ret | ||
fi | ||
|
||
local size | ||
size=$(echo "${blk_devices}" | jq .blockdevices | jq -r --arg name "vda" '.[] | select(.name == $name) | .size') | ||
if [[ $size != "${EXPECTED_ROOT_SIZE}" ]]; then | ||
return 1 | ||
fi | ||
|
||
local datavolume_sizes | ||
datavolume_sizes=$(echo "${blk_devices}" | jq .blockdevices | jq -r --arg name "vda" '.[] | select(.name != $name) | .size') | ||
for datavolume_size in ${datavolume_sizes}; do | ||
if [[ $datavolume_size != "${EXPECTED_DATA_SIZE}" ]]; then | ||
return 1 | ||
fi | ||
done | ||
|
||
return 0 | ||
} | ||
|
||
VMS=$(get_vms "${NAMESPACE}" "${LABEL_KEY}" "${LABEL_VALUE}") | ||
|
||
for vm in ${VMS}; do | ||
for attempt in $(seq 1 $MAX_RETRIES); do | ||
if ${COMMAND} "${vm}"; then | ||
break | ||
fi | ||
if [ "${attempt}" -lt $MAX_RETRIES ]; then | ||
if [ "${attempt}" -lt $MAX_SHORT_WAITS ]; then | ||
sleep "${SHORT_WAIT}" | ||
else | ||
sleep "${LONG_WAIT}" | ||
fi | ||
else | ||
echo "Failed waiting on ${COMMAND} for ${vm}" >&2 | ||
exit 1 | ||
fi | ||
done | ||
echo "${COMMAND} finished successfully for ${vm}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
spec: | ||
resources: | ||
requests: | ||
storage: {{ .storageSize }} |
7 changes: 7 additions & 0 deletions
7
cmd/config/virt-capacity-benchmark/templates/secret_ssh_public.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: "{{ .name }}-{{ .counter }}" | ||
type: Opaque | ||
data: | ||
key: {{ .publicKeyPath | ReadFile | b64enc }} |
14 changes: 14 additions & 0 deletions
14
cmd/config/virt-capacity-benchmark/templates/vm-snapshot.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: snapshot.kubevirt.io/v1beta1 | ||
kind: VirtualMachineSnapshot | ||
metadata: | ||
name: "{{ .name }}-{{ .counter }}-{{ .Replica }}" | ||
labels: | ||
{{range $key, $value := .snapshotLabels }} | ||
{{ $key }}: {{ $value }} | ||
{{end}} | ||
spec: | ||
deletionPolicy: delete | ||
source: | ||
apiGroup: kubevirt.io | ||
kind: VirtualMachine | ||
name: "{{ .name }}-{{ .counter }}-{{ .Replica }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{{- $storageClassName := .storageClassName -}} | ||
{{- $dataVolumeLabels := .dataVolumeLabels -}} | ||
{{- $dataVolumeSize := (default "1Gi" .dataVolumeSize) -}} | ||
{{- $name := .name -}} | ||
{{- $counter := .counter -}} | ||
{{- $replica := .Replica }} | ||
{{- $accessMode := .accessMode -}} | ||
|
||
apiVersion: kubevirt.io/v1 | ||
kind: VirtualMachine | ||
metadata: | ||
name: "{{ $name }}-{{ $counter }}-{{ $replica }}" | ||
labels: | ||
{{range $key, $value := .vmLabels }} | ||
{{ $key }}: {{ $value }} | ||
{{end}} | ||
spec: | ||
dataVolumeTemplates: | ||
- metadata: | ||
name: "{{ $name }}-{{ $counter }}-{{ $replica }}-root" | ||
labels: | ||
{{range $key, $value := .rootVolumeLabels }} | ||
{{ $key }}: {{ $value }} | ||
{{end}} | ||
spec: | ||
source: | ||
registry: | ||
url: "docker://{{ .rootDiskImage }}" | ||
storage: | ||
accessModes: | ||
- {{ $accessMode }} | ||
storageClassName: {{ .storageClassName }} | ||
resources: | ||
requests: | ||
storage: {{ default "10Gi" .rootVolumeSize }} | ||
{{ range $dataVolumeIndex := .dataVolumeCounters }} | ||
- metadata: | ||
name: "{{ $name }}-{{ $counter }}-{{ $replica }}-data-{{ $dataVolumeIndex }}" | ||
labels: | ||
{{range $key, $value := $dataVolumeLabels }} | ||
{{ $key }}: {{ $value }} | ||
{{end}} | ||
spec: | ||
source: | ||
blank: {} | ||
storage: | ||
accessModes: | ||
- {{ $accessMode }} | ||
storageClassName: {{ $storageClassName }} | ||
resources: | ||
requests: | ||
storage: {{ $dataVolumeSize }} | ||
{{ end }} | ||
running: true | ||
template: | ||
spec: | ||
accessCredentials: | ||
- sshPublicKey: | ||
propagationMethod: | ||
noCloud: {} | ||
source: | ||
secret: | ||
secretName: "{{ .sshPublicKeySecret }}-{{ .counter }}" | ||
architecture: amd64 | ||
domain: | ||
resources: | ||
requests: | ||
memory: {{ default "512Mi" .vmMemory }} | ||
devices: | ||
disks: | ||
- disk: | ||
bus: virtio | ||
name: rootdisk | ||
bootOrder: 1 | ||
{{ range $dataVolumeIndex := .dataVolumeCounters }} | ||
- disk: | ||
bus: virtio | ||
name: "data-{{ $dataVolumeIndex }}" | ||
{{ end }} | ||
interfaces: | ||
- name: default | ||
masquerade: {} | ||
bootOrder: 2 | ||
machine: | ||
type: pc-q35-rhel9.4.0 | ||
networks: | ||
- name: default | ||
pod: {} | ||
volumes: | ||
- dataVolume: | ||
name: "{{ .name }}-{{ .counter }}-{{ .Replica }}-root" | ||
name: rootdisk | ||
{{ range $dataVolumeIndex := .dataVolumeCounters }} | ||
- dataVolume: | ||
name: "{{ $name }}-{{ $counter }}-{{ $replica }}-data-{{ $dataVolumeIndex }}" | ||
name: "data-{{ . }}" | ||
{{ end }} | ||
- cloudInitNoCloud: | ||
userData: | | ||
#cloud-config | ||
chpasswd: | ||
expire: false | ||
password: {{ uuidv4 }} | ||
user: fedora | ||
runcmd: [] | ||
name: cloudinitdisk |
Oops, something went wrong.