kubevirt_vm: Use {Instancetype,Preference}Matchers

Use InstancetypeMatchers and PreferenceMatchers directly instead of
providing multiple arguments to prevent unnecessary abstraction.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
Felix Matouschek
2023-07-17 10:29:01 +02:00
parent 40972f61c2
commit b0971aca37
3 changed files with 21 additions and 74 deletions

View File

@@ -7,8 +7,10 @@
namespace: default namespace: default
labels: labels:
app: test app: test
instancetype: u1.medium instancetype:
preference: fedora name: u1.medium
preference:
name: fedora
interfaces: interfaces:
- name: default - name: default
masquerade: {} masquerade: {}

View File

@@ -73,44 +73,14 @@ options:
default: 180 default: 180
instancetype: instancetype:
description: description:
- Specify the instancetype of the VirtualMachine. - Specify the instancetype matcher of the VirtualMachine.
- Only used when I(state=present). - Only used when I(state=present).
type: str type: dict
preference: preference:
description: description:
- Specify the preference of the VirtualMachine. - Specify the preference matcher of the VirtualMachine.
- Only used when I(state=present).
type: str
infer_from_volume:
description:
- Specify volumes to infer an instancetype or a preference from.
- Only used when I(state=present). - Only used when I(state=present).
type: dict type: dict
suboptions:
instancetype:
description:
- Name of the volume to infer the instancetype from.
type: str
preference:
description:
- Name of the volume to infer the preference from.
type: str
clear_revision_name:
description:
- Specify to clear the revision name of the instancetype or preference.
- Only used when I(state=present).
type: dict
suboptions:
instancetype:
description:
- Clear the revision name of the instancetype.
type: bool
default: no
preference:
description:
- Clear the revision name of the preference.
type: bool
default: no
interfaces: interfaces:
description: description:
- Specify the interfaces of the VirtualMachine. - Specify the interfaces of the VirtualMachine.
@@ -163,8 +133,10 @@ EXAMPLES = """
namespace: default namespace: default
labels: labels:
app: test app: test
instancetype: u1.medium instancetype:
preference: fedora name: u1.medium
preference:
name: fedora
interfaces: interfaces:
- name: default - name: default
masquerade: {} masquerade: {}
@@ -278,29 +250,13 @@ metadata:
{{ labels | to_yaml | indent(4) }} {{ labels | to_yaml | indent(4) }}
{%- endif %} {%- endif %}
spec: spec:
{% if instancetype or infer_from_volume.instancetype %} {% if instancetype %}
instancetype: instancetype:
{% if instancetype %} {{ instancetype | to_yaml | indent(4) }}
name: "{{ instancetype }}"
{% endif %}
{% if infer_from_volume.instancetype %}
inferFromVolume: "{{ infer_from_volume.instancetype }}"
{% endif %}
{% if clear_revision_name.instancetype %}
revisionName: ""
{% endif %}
{% endif %} {% endif %}
{% if preference or infer_from_volume.preference %} {% if preference %}
preference: preference:
{% if preference %} {{ preference | to_yaml | indent(4) }}
name: "{{ preference }}"
{% endif %}
{% if infer_from_volume.preference %}
inferFromVolume: "{{ infer_from_volume.preference }}"
{% endif %}
{% if clear_revision_name.preference %}
revisionName: ""
{% endif %}
{% endif %} {% endif %}
running: {{ running }} running: {{ running }}
template: template:
@@ -362,19 +318,8 @@ def arg_spec() -> Dict:
"labels": {"type": "dict"}, "labels": {"type": "dict"},
"running": {"type": "bool", "default": True}, "running": {"type": "bool", "default": True},
"termination_grace_period": {"type": "int", "default": 180}, "termination_grace_period": {"type": "int", "default": 180},
"instancetype": {}, "instancetype": {"type": "dict"},
"preference": {}, "preference": {"type": "dict"},
"infer_from_volume": {
"type": "dict",
"options": {"instancetype": {}, "preference": {}},
},
"clear_revision_name": {
"type": "dict",
"options": {
"instancetype": {"type": "bool", "default": False},
"preference": {"type": "bool", "default": False},
},
},
"interfaces": {"type": "list", "elements": "dict"}, "interfaces": {"type": "list", "elements": "dict"},
"networks": {"type": "list", "elements": "dict"}, "networks": {"type": "list", "elements": "dict"},
"volumes": {"type": "list", "elements": "dict"}, "volumes": {"type": "list", "elements": "dict"},

View File

@@ -81,10 +81,10 @@ FIXTURE2 = {
'environment': 'staging' 'environment': 'staging'
}, },
'api_version': 'kubevirt.io/v1', 'running': True, 'termination_grace_period': 180, 'wait': False, 'wait_sleep': 5, 'wait_timeout': 120, 'force': False, 'api_version': 'kubevirt.io/v1', 'running': True, 'termination_grace_period': 180, 'wait': False, 'wait_sleep': 5, 'wait_timeout': 120, 'force': False,
'generate_name': None, 'annotations': None, 'instancetype': None, 'preference': None, 'infer_from_volume': None, 'clear_revision_name': None, 'generate_name': None, 'annotations': None, 'instancetype': None, 'preference': None, 'interfaces': None, 'networks': None, 'volumes': None,
'interfaces': None, 'networks': None, 'volumes': None, 'kubeconfig': None, 'context': None, 'host': None, 'api_key': None, 'username': None, 'kubeconfig': None, 'context': None, 'host': None, 'api_key': None, 'username': None, 'password': None, 'validate_certs': None, 'ca_cert': None,
'password': None, 'validate_certs': None, 'ca_cert': None, 'client_cert': None, 'client_key': None, 'proxy': None, 'no_proxy': None, 'proxy_headers': None, 'client_cert': None, 'client_key': None, 'proxy': None, 'no_proxy': None, 'proxy_headers': None, 'persist_config': None, 'impersonate_user': None,
'persist_config': None, 'impersonate_user': None, 'impersonate_groups': None, 'delete_options': None, 'impersonate_groups': None, 'delete_options': None,
'resource_definition': METADATA, 'resource_definition': METADATA,
'wait_condition': { 'wait_condition': {
'type': 'Ready', 'type': 'Ready',