Skip to content

Commit

Permalink
feat: download disk from multiple volumes
Browse files Browse the repository at this point in the history
Download disk image from VM that has
multiple volumes.

Signed-off-by: Ben Oukhanov <[email protected]>
  • Loading branch information
codingben committed Jan 17, 2024
1 parent 0fd7203 commit 47e5b5a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ KubeVirt Disk Uploader -> Download VM Disk -> Build New Container Disk -> Push T
**Prerequisites**

1. Ensure Virtual Machine (VM) is powered off. Data from VM can be exported only when it is not used.
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).
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).
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).

Deploy `kubevirt-disk-uploader` within the same namespace as the Virtual Machine (VM):
Expand Down
11 changes: 11 additions & 0 deletions examples/kubevirt-disk-uploader-tekton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ spec:
- name: VM_NAME
description: The name of the virtual machine
type: string
- name: VOLUME_NAME
description: The volume name of the virtual machine
type: string
- name: EXPORTED_IMAGE
description: The name of the exported image
type: string
Expand Down Expand Up @@ -188,6 +191,7 @@ spec:
command: ["/usr/local/bin/run-uploader.sh"]
args:
- $(params.VM_NAME)
- $(params.VOLUME_NAME)
- $(params.EXPORTED_IMAGE)
- $(params.DISK_IMAGE)
- $(params.ENABLE_VIRT_SYSPREP)
Expand All @@ -206,6 +210,9 @@ spec:
- name: VM_NAME
description: "Name of the virtual machine"
type: string
- name: VOLUME_NAME
description: "Volume name of the virtual machine"
type: string
- name: EXPORTED_IMAGE
description: "Name of the exported image"
type: string
Expand All @@ -227,6 +234,8 @@ spec:
params:
- name: VM_NAME
value: "$(params.VM_NAME)"
- name: VOLUME_NAME
value: "$(params.VOLUME_NAME)"
- name: EXPORTED_IMAGE
value: "$(params.EXPORTED_IMAGE)"
- name: DISK_IMAGE
Expand All @@ -249,6 +258,8 @@ spec:
params:
- name: VM_NAME
value: example-vm-tekton
- name: VOLUME_NAME
value: datavolumedisk
- name: EXPORTED_IMAGE
value: example-vm-tekton-exported:latest
- name: DISK_IMAGE
Expand Down
2 changes: 1 addition & 1 deletion kubevirt-disk-uploader.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
name: kubevirt-disk-uploader-credentials
key: registryHostname
command: ["/usr/local/bin/run-uploader.sh"]
# args: ["<VM_NAME>", "<CONTAINER_DISK_NAME>", "<DISK_FILE>", "<ENABLE_VIRT_SYSPREP>"]
# args: ["<VM_NAME>", "<VOLUME_NAME>", "<CONTAINER_DISK_NAME>", "<DISK_FILE>", "<ENABLE_VIRT_SYSPREP>"]
resources:
requests:
memory: 3Gi
Expand Down
14 changes: 10 additions & 4 deletions run-uploader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# Arguments
VM_NAME=$1
CONTAINER_DISK_NAME=$2
DISK_FILE=$3
ENABLE_VIRT_SYSPREP=$4
VOLUME_NAME=$2
CONTAINER_DISK_NAME=$3
DISK_FILE=$4
ENABLE_VIRT_SYSPREP=$5

# Variables
OUTPUT_PATH=./tmp
Expand All @@ -16,6 +17,11 @@ validate_arguments() {
exit 1
fi

if [ -z "$VOLUME_NAME" ]; then
echo "Volume name is missing. Please provide a valid Volume name."
exit 1
fi

if [ -z "$CONTAINER_DISK_NAME" ]; then
echo "Container Disk name is missing. Please provide a valid disk name."
exit 1
Expand Down Expand Up @@ -51,7 +57,7 @@ END
download_disk_img() {
echo "Downloading disk image $DISK_FILE from $VM_NAME Virutal Machine..."

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

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

0 comments on commit 47e5b5a

Please sign in to comment.