Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 47e5b5a

Browse files
committed
feat: download disk from multiple volumes
Download disk image from VM that has multiple volumes. Signed-off-by: Ben Oukhanov <[email protected]>
1 parent 0fd7203 commit 47e5b5a

4 files changed

+23
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ KubeVirt Disk Uploader -> Download VM Disk -> Build New Container Disk -> Push T
1515
**Prerequisites**
1616

1717
1. Ensure Virtual Machine (VM) is powered off. Data from VM can be exported only when it is not used.
18-
2. Modify [kubevirt-disk-uploader](https://github.com/codingben/kubevirt-disk-uploader/blob/main/kubevirt-disk-uploader.yaml#L58) arguments (VM Name, New Container Disk Name, Disk File, and Enable or Disable System Preparation).
18+
2. Modify [kubevirt-disk-uploader](https://github.com/codingben/kubevirt-disk-uploader/blob/main/kubevirt-disk-uploader.yaml#L58) arguments (VM Name, Volume Name, New Container Disk Name, Disk File, and Enable or Disable System Preparation).
1919
3. Modify [kubevirt-disk-uploader-credentials](https://github.com/codingben/kubevirt-disk-uploader/blob/main/kubevirt-disk-uploader.yaml#L65-L74) of the external container registry (Username, Password and Hostname).
2020

2121
Deploy `kubevirt-disk-uploader` within the same namespace as the Virtual Machine (VM):

examples/kubevirt-disk-uploader-tekton.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ spec:
157157
- name: VM_NAME
158158
description: The name of the virtual machine
159159
type: string
160+
- name: VOLUME_NAME
161+
description: The volume name of the virtual machine
162+
type: string
160163
- name: EXPORTED_IMAGE
161164
description: The name of the exported image
162165
type: string
@@ -188,6 +191,7 @@ spec:
188191
command: ["/usr/local/bin/run-uploader.sh"]
189192
args:
190193
- $(params.VM_NAME)
194+
- $(params.VOLUME_NAME)
191195
- $(params.EXPORTED_IMAGE)
192196
- $(params.DISK_IMAGE)
193197
- $(params.ENABLE_VIRT_SYSPREP)
@@ -206,6 +210,9 @@ spec:
206210
- name: VM_NAME
207211
description: "Name of the virtual machine"
208212
type: string
213+
- name: VOLUME_NAME
214+
description: "Volume name of the virtual machine"
215+
type: string
209216
- name: EXPORTED_IMAGE
210217
description: "Name of the exported image"
211218
type: string
@@ -227,6 +234,8 @@ spec:
227234
params:
228235
- name: VM_NAME
229236
value: "$(params.VM_NAME)"
237+
- name: VOLUME_NAME
238+
value: "$(params.VOLUME_NAME)"
230239
- name: EXPORTED_IMAGE
231240
value: "$(params.EXPORTED_IMAGE)"
232241
- name: DISK_IMAGE
@@ -249,6 +258,8 @@ spec:
249258
params:
250259
- name: VM_NAME
251260
value: example-vm-tekton
261+
- name: VOLUME_NAME
262+
value: datavolumedisk
252263
- name: EXPORTED_IMAGE
253264
value: example-vm-tekton-exported:latest
254265
- name: DISK_IMAGE

kubevirt-disk-uploader.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ spec:
5555
name: kubevirt-disk-uploader-credentials
5656
key: registryHostname
5757
command: ["/usr/local/bin/run-uploader.sh"]
58-
# args: ["<VM_NAME>", "<CONTAINER_DISK_NAME>", "<DISK_FILE>", "<ENABLE_VIRT_SYSPREP>"]
58+
# args: ["<VM_NAME>", "<VOLUME_NAME>", "<CONTAINER_DISK_NAME>", "<DISK_FILE>", "<ENABLE_VIRT_SYSPREP>"]
5959
resources:
6060
requests:
6161
memory: 3Gi

run-uploader.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
# Arguments
44
VM_NAME=$1
5-
CONTAINER_DISK_NAME=$2
6-
DISK_FILE=$3
7-
ENABLE_VIRT_SYSPREP=$4
5+
VOLUME_NAME=$2
6+
CONTAINER_DISK_NAME=$3
7+
DISK_FILE=$4
8+
ENABLE_VIRT_SYSPREP=$5
89

910
# Variables
1011
OUTPUT_PATH=./tmp
@@ -16,6 +17,11 @@ validate_arguments() {
1617
exit 1
1718
fi
1819

20+
if [ -z "$VOLUME_NAME" ]; then
21+
echo "Volume name is missing. Please provide a valid Volume name."
22+
exit 1
23+
fi
24+
1925
if [ -z "$CONTAINER_DISK_NAME" ]; then
2026
echo "Container Disk name is missing. Please provide a valid disk name."
2127
exit 1
@@ -51,7 +57,7 @@ END
5157
download_disk_img() {
5258
echo "Downloading disk image $DISK_FILE from $VM_NAME Virutal Machine..."
5359

54-
usr/bin/virtctl vmexport download "$VM_NAME" --vm="$VM_NAME" --output="$TEMP_DISK_PATH"
60+
usr/bin/virtctl vmexport download "$VM_NAME" --vm="$VM_NAME" --volume "$VOLUME_NAME" --output="$TEMP_DISK_PATH"
5561

5662
if [ -e "$TEMP_DISK_PATH" ] && [ -s "$TEMP_DISK_PATH" ]; then
5763
echo "Donwload completed successfully."

0 commit comments

Comments
 (0)