-
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.
Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
- Loading branch information
Showing
11 changed files
with
791 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,105 @@ | ||
#!/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=126 | ||
# In the first reties use a shorter sleep | ||
WAIT_TIMES=(1 2 3 5 10 20 30) | ||
|
||
if virtctl ssh --help | grep -qc "\--local-ssh " ; then | ||
LOCAL_SSH="--local-ssh" | ||
else | ||
LOCAL_SSH="" | ||
fi | ||
|
||
function 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}" | ||
} | ||
|
||
function 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}") | ||
local ret=$? | ||
if [ $ret -ne 0 ]; then | ||
return 1 | ||
fi | ||
echo "${output}" | ||
} | ||
|
||
function check_vm_running() { | ||
remote_command "${NAMESPACE}" "${IDENTITY_FILE}" "${REMOTE_USER}" "${vm}" "ls" | ||
return $? | ||
} | ||
|
||
function 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 | ||
counter=0 | ||
for attempt in $(seq 1 $MAX_RETRIES); do | ||
if ${COMMAND} "${vm}"; then | ||
break | ||
fi | ||
if [ "${attempt}" -lt $MAX_RETRIES ]; then | ||
if [ $counter -lt ${#WAIT_TIMES[@]} ]; then | ||
wait_time=${WAIT_TIMES[$counter]} | ||
else | ||
wait_time=${WAIT_TIMES[-1]} # Use the last value in the array | ||
fi | ||
sleep "${wait_time}" | ||
((counter++)) | ||
else | ||
exit 1 | ||
fi | ||
done | ||
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 }} |
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
apiVersion: snapshot.kubevirt.io/v1beta1 | ||
kind: VirtualMachineSnapshot | ||
metadata: | ||
name: "{{ .name }}-{{ .counter }}-{{ .Replica }}" | ||
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,101 @@ | ||
{{- $storageClassName := .storageClassName -}} | ||
{{- $dataVolumeLabels := .dataVolumeLabels -}} | ||
{{- $dataVolumeSize := (default "1Gi" .dataVolumeSize) -}} | ||
{{- $name := .name -}} | ||
{{- $counter := .counter -}} | ||
{{- $replica := .Replica }} | ||
|
||
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: | ||
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: | ||
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.