Skip to content

Commit 6a71c24

Browse files
committed
Update to use DataVolumes for imports
- Updated import as VM(linux/windows) to use DV. - Updated improt as Template(linux/windows) to use DV. Signed-off-by: Alexander Wels <[email protected]>
1 parent fb0f414 commit 6a71c24

File tree

9 files changed

+180
-142
lines changed

9 files changed

+180
-142
lines changed

README.md

+17-22
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ image is downloaded from the specified location. A virtual machine is created
1414
and associated with the imported disk image.
1515

1616
### Required credentials
17-
The current design of this APB requires that an OpenShift User and corresponding
18-
password be specified. This is a temporary inconvenience which should be
19-
removed in the near future. Please be sure to choose an account that has
20-
privileges to create resources (PVC and VirtualMachine(s)) in the chosen
21-
project.
17+
The current design of this APB requires that an admin OpenShift User and
18+
corresponding password be specified for certain operations. This is a
19+
temporary inconvenience which should be removed in the near future.
2220

2321
### Supported disk image formats
2422
This APB relies on the
@@ -30,32 +28,29 @@ format. Compressed images in the gz and xz formats are supported.
3028
The operating system installed in a virtual machine disk image may make certain
3129
assumptions about the underlying hardware platform. In order for the virtual
3230
machine to run properly, choose a virtual machine type that most closely matches
33-
the virtual machine being imported. *Currently only 'default' is available but
34-
more types will be added as needed.*
31+
the virtual machine being imported.
3532

3633
### Parameters
37-
| Parameter | Default value | Options | Comments |
38-
|:---------------------|:--------------|:----------|:----------|
39-
| Openshift User | | | *see above* |
40-
| Openshift Password | | | *see above* |
41-
| Disk Image URL | | | The location of the virtual machine disk image. |
42-
| Virtual Machine Type | default | <ul><li>default</li></ul> | *see above* |
43-
| Virtual Machine Name | | | Choose a unique name for the new virtual machine. |
44-
| Number of CPUs | 1 | | The number virtual CPU cores to assign to the virtual machine. |
45-
| Memory | 1024 | | The amount of memory (in Megabytes) to assign to the virtual machine. |
34+
| Parameter | Default value | Options | Comments |
35+
|:-------------------------|:--------------|:----------|:----------|
36+
| Openshift Admin User | | | Only needed to create templates |
37+
| Openshift Admin Password | | | Only needed to create templates |
38+
| Disk Image URL | | | The location of the virtual machine disk image. |
39+
| Virtual Machine Type | linux | <ul><li>linux</li><li>windows</li></ul> | |
40+
| Virtual Machine Name | | | Choose a unique name for the new virtual machine. |
41+
| Number of CPUs | 1 | | The number virtual CPU cores to assign to the virtual machine. |
42+
| Memory | 1024 | | The amount of memory (in Megabytes) to assign to the virtual machine. |
4643

4744
## Import from VMWare
4845
To use this option, select the *Import from VMWare* plan. You will need to supply
4946
VMware's url from where you want to import, virtual machine name to be imported
5047
and the VMware's administrator credentials. Once deployed, a virtual machine is
5148
created with a PVC containing imported image from VMware.
5249

53-
### Required credentials
54-
The current design of this APB requires that an OpenShift User and corresponding
55-
password be specified. This is a temporary inconvenience which should be
56-
removed in the near future. Please be sure to choose an account that has
57-
privileges to create resources (PVC and VirtualMachine(s)) in the chosen
58-
project.
50+
###
51+
In order for this apb to work you need at a minimum the following versions:
52+
CDI: 1.2.0
53+
KubeVirt: 0.9
5954

6055
### Limitations
6156
At the moment we can import virtual machine having one disk and one network interface.

roles/import-from-url/tasks/deprovision.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
block:
2222
- command: "oc login --insecure-skip-tls-verify=true -u {{ admin_user }} -p {{ admin_password }}"
2323
- command: "oc delete template -l import-vm-apb/transaction_id={{ _apb_service_instance_id }} -n openshift --ignore-not-found=true"
24+
- command: "oc delete dv -l import-vm-apb/transaction_id={{ _apb_service_instance_id }} -n {{ namespace }} --ignore-not-found=true"
2425
- name: Get current relist count"
2526
command: "oc get clusterservicebroker template-service-broker -o jsonpath='{.spec.relistRequests}'"
2627
register: current_relist_count
2728
- command: "oc patch clusterservicebroker template-service-broker -p '{\"spec\": {\"relistRequests\": {{ current_relist_count.stdout|int + 1 }} }}'"
2829
ignore_errors: yes
2930
when: image_type == "template"
30-
31-
- name: Delete PVC
32-
command: "oc delete pvc -l import-vm-apb/transaction_id={{ _apb_service_instance_id }} --ignore-not-found=true"

roles/import-from-url/tasks/provision.yml

+21-42
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
# Before doing anything check if the PVC already exists, if it
2020
# does, then don't waste the effor to look stuff up as it will
21+
# We want to look for PVC and not DVs because DVs are just an abstraction on top of PVCs and
22+
# the real thing to check for are the PVCs
2123
# fail.
2224
- name: Check for existing PVC
23-
command: "oc get pvc {{image_type}}-{{ vm_name }}-disk-01"
25+
command: "oc get pvc {{image_type}}-{{ vm_name }}-dv-01"
2426
register: pvc_exists
2527
# This looks odd, the oc command queries for the pvc, and we continue if there is
26-
# an error (it can't find the PVC) and no stdout output. This won't solve a race
28+
# an error (it can't find the pvc) and no stdout output. This won't solve a race
2729
# condition, but its a useful first check regardless.
2830
failed_when: pvc_exists.stdout != ""
2931

@@ -33,56 +35,33 @@
3335
method: HEAD
3436
register: response
3537

36-
- name: Calculate PVC size
38+
- name: Calculate DV size
3739
set_fact:
3840
# Use 4% FS overhead based on this research
3941
# https://rwmj.wordpress.com/2009/11/08/filesystem-metadata-overhead/
4042
size_bytes: "{{ (response.content_length|int * 1.04)|int }}"
4143
when: disk_size_gb == 0
4244

43-
- name: Calculate PVC size
45+
- name: Calculate DV size
4446
set_fact:
4547
size_bytes: "{{ (disk_size_gb|int * 1073741824 * 1.04)|int }}"
4648
when: disk_size_gb != 0
4749

48-
- name: Build PVC
49-
template:
50-
src: cdi-pvc.yml
51-
dest: /tmp/pvc.yml
52-
53-
- name: Debug generated pvc
54-
command: cat /tmp/pvc.yml
55-
register: debug_out
56-
- name: Show generated pvc
57-
debug:
58-
msg: "{{ debug_out.stdout }}"
59-
60-
- name: Provision PVC
61-
command: "oc create -f /tmp/pvc.yml"
62-
63-
- name: Check PVC bound status
64-
command: "oc get pvc {{image_type}}-{{ vm_name }}-disk-01 -o jsonpath='{ {{pvc_status_path}} }'"
65-
register: pvc_bound_status
66-
until: pvc_bound_status.stdout == 'Bound'
67-
retries: 60
68-
delay: 3
69-
70-
- name: Pod Import Status
71-
command: "oc get pvc {{image_type}}-{{ vm_name }}-disk-01 -o jsonpath='{ {{import_status_path}} }'"
72-
register: import_status
73-
# The values of import_status follow standard kubernetes pod phase values. Pending/Running/Succeeded/Failed/Unknown
74-
# The importer POD will update the status.
75-
until: import_status.stdout == 'Succeeded' or import_status.stdout == 'Failed'
76-
retries: 17280 # This equates to a day of retries. It could take a while to import the disk, so give it a long timeout.
77-
delay: 5
78-
79-
- fail:
80-
msg: "Unable to import image into PVC, check importer pod log for details."
81-
when: import_status.stdout != 'Succeeded'
82-
83-
- name: Set pvc_name
84-
set_fact:
85-
pvc_name: "{{image_type}}-{{ vm_name }}-disk-01"
50+
- name: Build Template DV
51+
block:
52+
- name: Create DV yaml
53+
template:
54+
src: cdi-dv.yml
55+
dest: /tmp/dv.yml
56+
- name: Debug generated DV
57+
command: cat /tmp/dv.yml
58+
register: debug_out
59+
- name: Show generated DV
60+
debug:
61+
msg: "{{ debug_out.stdout }}"
62+
- name: Provision DV
63+
command: "oc create -f /tmp/dv.yml"
64+
when: image_type == "template"
8665

8766
- name: Set disk_bus
8867
set_fact:
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: cdi.kubevirt.io/v1alpha1
2+
kind: DataVolume
3+
metadata:
4+
name: "{{ image_type }}-{{ vm_name }}-dv-01"
5+
labels:
6+
import-vm-apb/transaction_id: "{{ _apb_service_instance_id }}"
7+
spec:
8+
source:
9+
http:
10+
url: "{{ disk_image_url }}"
11+
pvc:
12+
{% if storage_class is defined %}
13+
storageClassName: {{ storage_class }}
14+
{% endif %}
15+
accessModes:
16+
- ReadWriteOnce
17+
resources:
18+
requests:
19+
storage: "{{ size_bytes|int }}"

roles/import-from-url/templates/cdi-pvc.yml

-17
This file was deleted.

templates/linux-template.j2

+34-26
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ metadata:
44
name: {{ vm_name }}-template
55
namespace: openshift
66
annotations:
7-
description: "OCP KubeVirt Red Hat Enterprise Linux 7.4 VM template"
7+
description: "OCP KubeVirt Linux VM template"
88
tags: "kubevirt,ocp,template,linux,virtualmachine"
99
iconClass: icon-other-linux
1010
labels:
11-
kubevirt.io/os: rhel7.4
11+
kubevirt.io/os: linux
1212
miq.github.io/kubevirt-is-vm-template: "true"
1313
import-vm-apb/transaction_id: "{{ _apb_service_instance_id }}"
1414

@@ -17,43 +17,51 @@ objects:
1717
kind: VirtualMachine
1818
metadata:
1919
name: ${NAME}
20+
labels:
21+
kubevirt.io/vm: ${NAME}
2022
spec:
23+
dataVolumeTemplates:
24+
- metadata:
25+
name: vm-${NAME}-dv-01
26+
spec:
27+
pvc:
28+
{% if storage_class is defined %}
29+
storageClassName: {{ storage_class }}
30+
{% endif %}
31+
accessModes:
32+
- ReadWriteOnce
33+
resources:
34+
requests:
35+
storage: {{ disk_size_bytes }}
36+
source:
37+
pvc:
38+
namespace: "{{ namespace }}"
39+
name: "{{ image_type }}-{{ vm_name }}-dv-01"
2140
running: false
2241
template:
42+
metadata:
43+
labels:
44+
kubevirt.io/vm: {{ vm_name }}
2345
spec:
46+
terminationGracePeriodSeconds: 0
2447
domain:
2548
cpu:
2649
cores: ${{'{{'}}CPU_CORES{{'}}'}}
50+
machine:
51+
type: q35
2752
resources:
2853
requests:
2954
memory: ${MEMORY}
30-
machine:
31-
type: q35
3255
devices:
3356
disks:
34-
- name: disk0
35-
disk:
36-
bus: {{ disk_bus }}
37-
volumeName: volume-1
57+
- name: disk0
58+
disk:
59+
bus: {{ disk_bus }}
60+
volumeName: "${NAME}-datavolume"
3861
volumes:
39-
- name: volume-1
40-
persistentVolumeClaim:
41-
claimName: vm-${NAME}-disk-01
42-
- apiVersion: v1
43-
kind: PersistentVolumeClaim
44-
metadata:
45-
name: vm-${NAME}-disk-01
46-
annotations:
47-
k8s.io/CloneRequest: {{ namespace }}/{{ pvc_name }}
48-
spec:
49-
{% if storage_class is defined %}
50-
storageClassName: {{ storage_class }}
51-
{% endif %}
52-
accessModes:
53-
- ReadWriteOnce
54-
resources:
55-
requests:
56-
storage: {{ disk_size_bytes }}
62+
- dataVolume:
63+
name: "vm-${NAME}-dv-01"
64+
name: "${NAME}-datavolume"
5765
parameters:
5866
- name: NAME
5967
description: Name for the new VM

templates/linux-vm.j2

+30-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,38 @@ kind: VirtualMachine
33
metadata:
44
name: {{ vm_name }}
55
labels:
6-
import-vm-apb/transaction_id: {{ _apb_service_instance_id }}
6+
import-vm-apb/transaction_id: "{{ _apb_service_instance_id }}"
7+
kubevirt.io/vm: {{ vm_name }}
78
spec:
9+
dataVolumeTemplates:
10+
- metadata:
11+
name: "{{ image_type }}-{{ vm_name }}-dv-01"
12+
spec:
13+
pvc:
14+
accessModes:
15+
- ReadWriteOnce
16+
resources:
17+
requests:
18+
storage: {{ size_bytes|int }}
19+
{% if storage_class is defined %}
20+
storageClassName: {{ storage_class }}
21+
{% endif %}
22+
source:
23+
http:
24+
url: {{ disk_image_url }}
25+
status: {}
826
running: false
927
template:
28+
metadata:
29+
labels:
30+
kubevirt.io/vm: {{ vm_name }}
1031
spec:
1132
terminationGracePeriodSeconds: 0
1233
domain:
1334
cpu:
1435
cores: {{ nr_cores }}
36+
machine:
37+
type: q35
1538
resources:
1639
requests:
1740
memory: {{ mem }}{{ mem_unit }}
@@ -20,8 +43,10 @@ spec:
2043
- name: disk-1
2144
disk:
2245
bus: {{ disk_bus }}
23-
volumeName: volume-1
46+
volumeName: "{{ vm_name }}-datavolumevolume"
2447
volumes:
25-
- name: volume-1
26-
persistentVolumeClaim:
27-
claimName: {{ pvc_name }}
48+
- dataVolume:
49+
name: "{{ image_type }}-{{ vm_name }}-dv-01"
50+
name: "{{ vm_name }}-datavolumevolume"
51+
status: {}
52+

0 commit comments

Comments
 (0)