From 47e5b5ad72238b1983288274afeaa7a46577a5c1 Mon Sep 17 00:00:00 2001 From: Ben Oukhanov Date: Wed, 17 Jan 2024 17:40:04 +0200 Subject: [PATCH] feat: download disk from multiple volumes Download disk image from VM that has multiple volumes. Signed-off-by: Ben Oukhanov --- README.md | 2 +- examples/kubevirt-disk-uploader-tekton.yaml | 11 +++++++++++ kubevirt-disk-uploader.yaml | 2 +- run-uploader.sh | 14 ++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d2bf124..157c510 100644 --- a/README.md +++ b/README.md @@ -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): diff --git a/examples/kubevirt-disk-uploader-tekton.yaml b/examples/kubevirt-disk-uploader-tekton.yaml index c83b2b6..9695081 100644 --- a/examples/kubevirt-disk-uploader-tekton.yaml +++ b/examples/kubevirt-disk-uploader-tekton.yaml @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/kubevirt-disk-uploader.yaml b/kubevirt-disk-uploader.yaml index 097e7e5..fa00a18 100644 --- a/kubevirt-disk-uploader.yaml +++ b/kubevirt-disk-uploader.yaml @@ -55,7 +55,7 @@ spec: name: kubevirt-disk-uploader-credentials key: registryHostname command: ["/usr/local/bin/run-uploader.sh"] - # args: ["", "", "", ""] + # args: ["", "", "", "", ""] resources: requests: memory: 3Gi diff --git a/run-uploader.sh b/run-uploader.sh index e04af21..5cdef11 100755 --- a/run-uploader.sh +++ b/run-uploader.sh @@ -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 @@ -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 @@ -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."