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

Commit 0fd7203

Browse files
committed
feat: prepare disk image
Prepare disk image by running virt-sysprep before uploading it to container registry. Jira-Url: https://issues.redhat.com/browse/CNV-34270 Signed-off-by: Ben Oukhanov <[email protected]>
1 parent 5f2c7a1 commit 0fd7203

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN cd /usr/bin && \
1313
chmod +x virtctl && \
1414
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
1515
chmod +x kubectl && \
16-
microdnf install -y gzip qemu-img && \
16+
microdnf install -y gzip qemu-img libguestfs-tools-c && \
1717
microdnf clean all -y
1818
COPY --from=builder /app/kubevirt-disk-uploader /usr/local/bin/kubevirt-disk-uploader
1919
COPY run-uploader.sh /usr/local/bin/run-uploader.sh

README.md

Lines changed: 1 addition & 1 deletion
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, and Disk File).
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).
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ spec:
163163
- name: DISK_IMAGE
164164
description: The name of the disk image
165165
type: string
166+
- name: ENABLE_VIRT_SYSPREP
167+
description: Enable or disable preparation of disk image
168+
type: string
166169
steps:
167170
- name: kubevirt-disk-uploader-step
168171
image: quay.io/boukhano/kubevirt-disk-uploader:latest
@@ -187,6 +190,7 @@ spec:
187190
- $(params.VM_NAME)
188191
- $(params.EXPORTED_IMAGE)
189192
- $(params.DISK_IMAGE)
193+
- $(params.ENABLE_VIRT_SYSPREP)
190194
resources:
191195
requests:
192196
memory: "3Gi"
@@ -208,6 +212,9 @@ spec:
208212
- name: DISK_IMAGE
209213
description: "Name of the disk image"
210214
type: string
215+
- name: ENABLE_VIRT_SYSPREP
216+
description: "Enable or disable preparation of disk image"
217+
type: string
211218
tasks:
212219
- name: deploy-example-vm
213220
taskRef:
@@ -224,6 +231,8 @@ spec:
224231
value: "$(params.EXPORTED_IMAGE)"
225232
- name: DISK_IMAGE
226233
value: "$(params.DISK_IMAGE)"
234+
- name: ENABLE_VIRT_SYSPREP
235+
value: "$(params.ENABLE_VIRT_SYSPREP)"
227236
- name: deploy-example-vm-exported
228237
taskRef:
229238
name: example-vm-exported-task
@@ -244,4 +253,6 @@ spec:
244253
value: example-vm-tekton-exported:latest
245254
- name: DISK_IMAGE
246255
value: disk.img.gz
256+
- name: ENABLE_VIRT_SYSPREP
257+
value: true
247258
serviceAccountName: kubevirt-disk-uploader-tekton

kubevirt-disk-uploader.yaml

Lines changed: 1 addition & 1 deletion
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>"]
58+
# args: ["<VM_NAME>", "<CONTAINER_DISK_NAME>", "<DISK_FILE>", "<ENABLE_VIRT_SYSPREP>"]
5959
resources:
6060
requests:
6161
memory: 3Gi

run-uploader.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
VM_NAME=$1
55
CONTAINER_DISK_NAME=$2
66
DISK_FILE=$3
7+
ENABLE_VIRT_SYSPREP=$4
78

89
# Variables
910
OUTPUT_PATH=./tmp
@@ -24,6 +25,11 @@ validate_arguments() {
2425
echo "Disk file to extract is missing. Please provide a valid disk file."
2526
exit 1
2627
fi
28+
29+
if [ -z "$ENABLE_VIRT_SYSPREP" ]; then
30+
echo "ENABLE_VIRT_SYSPREP is missing or empty. Please provide a valid value (true or false)."
31+
exit 1
32+
fi
2733
}
2834

2935
apply_vmexport() {
@@ -69,6 +75,19 @@ convert_disk_img() {
6975
fi
7076
}
7177

78+
prep_disk_img() {
79+
if [ "$ENABLE_VIRT_SYSPREP" = "true" ]; then
80+
echo "Preparing disk image..."
81+
82+
DISK_PATH=$OUTPUT_PATH/disk.qcow2
83+
export LIBGUESTFS_BACKEND=direct
84+
85+
virt-sysprep --format qcow2 -a $DISK_PATH
86+
else
87+
echo "Skipping disk image preparation."
88+
fi
89+
}
90+
7291
upload_container_img() {
7392
echo "Building and uploading new container image with exported disk image..."
7493

@@ -85,6 +104,7 @@ main() {
85104
apply_vmexport
86105
download_disk_img
87106
convert_disk_img
107+
prep_disk_img
88108
upload_container_img
89109

90110
echo "Succesfully extracted disk image and uploaded it in a new container image to container registry."

0 commit comments

Comments
 (0)