mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-03-27 03:13:10 +00:00
Merge pull request #4 from 0xFelix/dvt
kubevirt_vm: Allow to specify DataVolume templates
This commit is contained in:
41
examples/play-create-dv.yml
Normal file
41
examples/play-create-dv.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
- name: Create VM
|
||||
kubernetes.kubevirt.kubevirt_vm:
|
||||
state: present
|
||||
name: testvm-with-dv
|
||||
namespace: default
|
||||
labels:
|
||||
app: test
|
||||
instancetype:
|
||||
name: u1.medium
|
||||
preference:
|
||||
name: fedora
|
||||
data_volume_templates:
|
||||
- metadata:
|
||||
name: testdv
|
||||
spec:
|
||||
source:
|
||||
registry:
|
||||
url: docker://quay.io/containerdisks/fedora:latest
|
||||
storage:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
spec:
|
||||
domain:
|
||||
devices: {}
|
||||
volumes:
|
||||
- dataVolume:
|
||||
name: testdv
|
||||
name: datavolume
|
||||
- cloudInitNoCloud:
|
||||
userData: |-
|
||||
#cloud-config
|
||||
# The default username is: fedora
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAA...
|
||||
name: cloudinit
|
||||
wait: yes
|
||||
8
examples/play-delete-dv.yml
Normal file
8
examples/play-delete-dv.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
- name: Delete VM
|
||||
kubernetes.kubevirt.kubevirt_vm:
|
||||
name: testvm-with-dv
|
||||
namespace: default
|
||||
state: absent
|
||||
wait: yes
|
||||
@@ -29,6 +29,7 @@ set_default_params() {
|
||||
KUBECTL_VERSION=${KUBECTL_VERSION:-v1.27.3}
|
||||
|
||||
KUBEVIRT_VERSION=${KUBEVIRT_VERSION:-v1.0.0}
|
||||
KUBEVIRT_CDI_VERSION=${KUBEVIRT_CDI_VERSION:-v1.56.0}
|
||||
KUBEVIRT_COMMON_INSTANCETYPES_VERSION=${KUBEVIRT_COMMON_INSTANCETYPES_VERSION:-v0.3.0}
|
||||
KUBEVIRT_USE_EMULATION=${KUBEVIRT_USE_EMULATION:-"false"}
|
||||
|
||||
@@ -175,6 +176,12 @@ is_nested_virt_enabled() {
|
||||
[ "$kvm_nested" == "1" ] || [ "$kvm_nested" == "Y" ] || [ "$kvm_nested" == "y" ]
|
||||
}
|
||||
|
||||
deploy_kubevirt_containerized_data_importer() {
|
||||
echo "Deploying KubeVirt containerized-data-importer"
|
||||
${KUBECTL} apply -f "https://github.com/kubevirt/containerized-data-importer/releases/download/${KUBEVIRT_CDI_VERSION}/cdi-operator.yaml"
|
||||
${KUBECTL} apply -f "https://github.com/kubevirt/containerized-data-importer/releases/download/${KUBEVIRT_CDI_VERSION}/cdi-cr.yaml"
|
||||
}
|
||||
|
||||
deploy_kubevirt_common_instancetypes() {
|
||||
echo "Deploying KubeVirt common-instancetypes"
|
||||
${KUBECTL} apply -f "https://github.com/kubevirt/common-instancetypes/releases/download/${KUBEVIRT_COMMON_INSTANCETYPES_VERSION}/common-instancetypes-all-bundle-${KUBEVIRT_COMMON_INSTANCETYPES_VERSION}.yaml"
|
||||
@@ -255,6 +262,7 @@ set_default_options() {
|
||||
OPT_CREATE_CLUSTER=false
|
||||
OPT_CONFIGURE_SECONDARY_NETWORK=false
|
||||
OPT_DEPLOY_KUBEVIRT=false
|
||||
OPT_DEPLOY_KUBEVIRT_CDI=false
|
||||
OPT_DEPLOY_KUBEVIRT_COMMON_INSTANCETYPES=false
|
||||
OPT_DEPLOY_CNAO=false
|
||||
OPT_CREATE_NAD=false
|
||||
@@ -270,6 +278,7 @@ parse_args() {
|
||||
--create-cluster) OPT_CREATE_CLUSTER=true ;;
|
||||
--configure-secondary-network) OPT_CONFIGURE_SECONDARY_NETWORK=true ;;
|
||||
--deploy-kubevirt) OPT_DEPLOY_KUBEVIRT=true ;;
|
||||
--deploy-kubevirt-cdi) OPT_DEPLOY_KUBEVIRT_CDI=true ;;
|
||||
--deploy-kubevirt-common-instancetypes) OPT_DEPLOY_KUBEVIRT_COMMON_INSTANCETYPES=true ;;
|
||||
--deploy-cnao) OPT_DEPLOY_CNAO=true ;;
|
||||
--create-nad) OPT_CREATE_NAD=true ;;
|
||||
@@ -310,6 +319,7 @@ if [ "${ARGCOUNT}" -eq "0" ]; then
|
||||
OPT_CREATE_CLUSTER=true
|
||||
OPT_CONFIGURE_SECONDARY_NETWORK=true
|
||||
OPT_DEPLOY_KUBEVIRT=true
|
||||
OPT_DEPLOY_KUBEVIRT_CDI=true
|
||||
OPT_DEPLOY_KUBEVIRT_COMMON_INSTANCETYPES=true
|
||||
OPT_DEPLOY_CNAO=true
|
||||
OPT_CREATE_NAD=true
|
||||
@@ -344,6 +354,10 @@ if [ "${OPT_DEPLOY_KUBEVIRT}" == true ]; then
|
||||
deploy_kubevirt
|
||||
fi
|
||||
|
||||
if [ "${OPT_DEPLOY_KUBEVIRT_CDI}" == true ]; then
|
||||
deploy_kubevirt_containerized_data_importer
|
||||
fi
|
||||
|
||||
if [ "${OPT_DEPLOY_KUBEVIRT_COMMON_INSTANCETYPES}" == true ]; then
|
||||
deploy_kubevirt_common_instancetypes
|
||||
fi
|
||||
|
||||
@@ -75,6 +75,12 @@ options:
|
||||
- Specify the preference matcher of the VirtualMachine.
|
||||
- Only used when I(state=present).
|
||||
type: dict
|
||||
data_volume_templates:
|
||||
description:
|
||||
- Specify the DataVolume templates of the VirtualMachine.
|
||||
- 'See: http://kubevirt.io/api-reference/v1.0.0/definitions.html#_v1_datavolumetemplatespec'
|
||||
type: list
|
||||
elements: 'dict'
|
||||
spec:
|
||||
description:
|
||||
- Specify the template spec of the VirtualMachine.
|
||||
@@ -144,6 +150,46 @@ EXAMPLES = """
|
||||
- ssh-ed25519 AAAA...
|
||||
name: cloudinit
|
||||
|
||||
- name: Create a VirtualMachine with a DataVolume template
|
||||
kubernetes.kubevirt.kubevirt_vm:
|
||||
state: present
|
||||
name: testvm-with-dv
|
||||
namespace: default
|
||||
labels:
|
||||
app: test
|
||||
instancetype:
|
||||
name: u1.medium
|
||||
preference:
|
||||
name: fedora
|
||||
data_volume_templates:
|
||||
- metadata:
|
||||
name: testdv
|
||||
spec:
|
||||
source:
|
||||
registry:
|
||||
url: docker://quay.io/containerdisks/fedora:latest
|
||||
storage:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
spec:
|
||||
domain:
|
||||
devices: {}
|
||||
volumes:
|
||||
- dataVolume:
|
||||
name: testdv
|
||||
name: datavolume
|
||||
- cloudInitNoCloud:
|
||||
userData: |-
|
||||
#cloud-config
|
||||
# The default username is: fedora
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAA...
|
||||
name: cloudinit
|
||||
wait: yes
|
||||
|
||||
- name: Delete a VirtualMachine
|
||||
kubernetes.kubevirt.kubevirt_vm:
|
||||
name: testvm
|
||||
@@ -243,6 +289,10 @@ spec:
|
||||
preference:
|
||||
{{ preference | to_yaml | indent(4) }}
|
||||
{% endif %}
|
||||
{% if data_volume_templates %}
|
||||
dataVolumeTemplates:
|
||||
{{ data_volume_templates | to_yaml | indent(4) }}
|
||||
{%- endif %}
|
||||
template:
|
||||
{% if annotations or labels %}
|
||||
metadata:
|
||||
@@ -292,6 +342,7 @@ def arg_spec() -> Dict:
|
||||
"running": {"type": "bool", "default": True},
|
||||
"instancetype": {"type": "dict"},
|
||||
"preference": {"type": "dict"},
|
||||
"data_volume_templates": {"type": "list", "elements": "dict"},
|
||||
"spec": {"type": "dict"},
|
||||
"wait": {"type": "bool", "default": False},
|
||||
"wait_sleep": {"type": "int", "default": 5},
|
||||
|
||||
@@ -35,6 +35,30 @@ FIXTURE1 = {
|
||||
},
|
||||
"spec": {
|
||||
"running": True,
|
||||
"dataVolumeTemplates": [
|
||||
{
|
||||
"metadata": {
|
||||
"name": "testdv"
|
||||
},
|
||||
"spec": {
|
||||
"source": {
|
||||
"registry": {
|
||||
"url": "docker://quay.io/containerdisks/fedora:latest"
|
||||
},
|
||||
},
|
||||
"storage": {
|
||||
"accessModes": [
|
||||
"ReadWriteOnce"
|
||||
],
|
||||
"resources": {
|
||||
"requests": {
|
||||
"storage": "5Gi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"template": {
|
||||
"metadata": {
|
||||
"labels": {
|
||||
@@ -62,6 +86,19 @@ metadata:
|
||||
service: loadbalancer
|
||||
spec:
|
||||
running: True
|
||||
dataVolumeTemplates:
|
||||
- metadata:
|
||||
name: testdv
|
||||
spec:
|
||||
source:
|
||||
registry:
|
||||
url: docker://quay.io/containerdisks/fedora:latest
|
||||
storage:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
@@ -81,6 +118,30 @@ FIXTURE2 = {
|
||||
'service': 'loadbalancer',
|
||||
'environment': 'staging'
|
||||
},
|
||||
'data_volume_templates': [
|
||||
{
|
||||
'metadata': {
|
||||
'name': 'testdv'
|
||||
},
|
||||
'spec': {
|
||||
'source': {
|
||||
'registry': {
|
||||
'url': 'docker://quay.io/containerdisks/fedora:latest'
|
||||
},
|
||||
},
|
||||
'storage': {
|
||||
'accessModes': [
|
||||
'ReadWriteOnce'
|
||||
],
|
||||
'resources': {
|
||||
'requests': {
|
||||
'storage': '5Gi'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
'spec': {
|
||||
'domain': {
|
||||
'devices': {}
|
||||
@@ -135,6 +196,30 @@ class TestCreateVM(unittest.TestCase):
|
||||
"service": "loadbalancer",
|
||||
"environment": "staging"
|
||||
},
|
||||
'data_volume_templates': [
|
||||
{
|
||||
'metadata': {
|
||||
'name': 'testdv'
|
||||
},
|
||||
'spec': {
|
||||
'source': {
|
||||
'registry': {
|
||||
'url': 'docker://quay.io/containerdisks/fedora:latest'
|
||||
},
|
||||
},
|
||||
'storage': {
|
||||
'accessModes': [
|
||||
'ReadWriteOnce'
|
||||
],
|
||||
'resources': {
|
||||
'requests': {
|
||||
'storage': '5Gi'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
'spec': {
|
||||
'domain': {
|
||||
'devices': {}
|
||||
|
||||
Reference in New Issue
Block a user