mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-07-28 18:34:36 +00:00
feat(modules): Add hidden_fields argument
Add the hidden_fields argument to kubevirt_vm and kubevirt_{vm,vmi}_info
which allows to hide and ignore certain fields in the returned definition
of a VM or VMI. By default this argument is set to ignore changes to the
kubemacpool.io/transaction-timestamp annotation and managed fields, which
may change at any time and cause the modules to return a changed status
although nothing has changed other than their values.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
@@ -43,6 +43,7 @@ def execute_info_module(module, kind, wait_condition):
|
|||||||
wait=module.params["wait"],
|
wait=module.params["wait"],
|
||||||
wait_sleep=module.params["wait_sleep"],
|
wait_sleep=module.params["wait_sleep"],
|
||||||
wait_timeout=module.params["wait_timeout"],
|
wait_timeout=module.params["wait_timeout"],
|
||||||
|
hidden_fields=module.params["hidden_fields"],
|
||||||
condition=wait_condition,
|
condition=wait_condition,
|
||||||
)
|
)
|
||||||
module.exit_json(changed=False, **facts)
|
module.exit_json(changed=False, **facts)
|
||||||
|
|||||||
@@ -158,6 +158,15 @@ options:
|
|||||||
- If set to O(force=yes), and O(state=present) is set, an existing object will be replaced.
|
- If set to O(force=yes), and O(state=present) is set, an existing object will be replaced.
|
||||||
type: bool
|
type: bool
|
||||||
default: no
|
default: no
|
||||||
|
hidden_fields:
|
||||||
|
description:
|
||||||
|
- Hide fields matching this option in the result.
|
||||||
|
- An example might be O(hidden_fields=[metadata.managedFields])
|
||||||
|
or O(hidden_fields=[metadata.annotations[kubemacpool.io/transaction-timestamp]]).
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
default: ['metadata.annotations[kubemacpool.io/transaction-timestamp]', metadata.managedFields]
|
||||||
|
version_added: 2.2.0
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.9"
|
- "python >= 3.9"
|
||||||
@@ -402,6 +411,14 @@ def arg_spec() -> Dict:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"hidden_fields": {
|
||||||
|
"type": "list",
|
||||||
|
"elements": "str",
|
||||||
|
"default": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
spec.update(deepcopy(AUTH_ARG_SPEC))
|
spec.update(deepcopy(AUTH_ARG_SPEC))
|
||||||
spec.update(deepcopy(COMMON_ARG_SPEC))
|
spec.update(deepcopy(COMMON_ARG_SPEC))
|
||||||
|
|||||||
@@ -74,6 +74,15 @@ options:
|
|||||||
- Ignored if O(wait) is not set.
|
- Ignored if O(wait) is not set.
|
||||||
default: 120
|
default: 120
|
||||||
type: int
|
type: int
|
||||||
|
hidden_fields:
|
||||||
|
description:
|
||||||
|
- Hide fields matching this option in the result.
|
||||||
|
- An example might be O(hidden_fields=[metadata.managedFields])
|
||||||
|
or O(hidden_fields=[metadata.annotations[kubemacpool.io/transaction-timestamp]]).
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
default: ['metadata.annotations[kubemacpool.io/transaction-timestamp]', metadata.managedFields]
|
||||||
|
version_added: 2.2.0
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.9"
|
- "python >= 3.9"
|
||||||
@@ -174,6 +183,14 @@ def arg_spec():
|
|||||||
"""
|
"""
|
||||||
spec = {
|
spec = {
|
||||||
"running": {"type": "bool"},
|
"running": {"type": "bool"},
|
||||||
|
"hidden_fields": {
|
||||||
|
"type": "list",
|
||||||
|
"elements": "str",
|
||||||
|
"default": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
spec.update(deepcopy(INFO_ARG_SPEC))
|
spec.update(deepcopy(INFO_ARG_SPEC))
|
||||||
spec.update(deepcopy(AUTH_ARG_SPEC))
|
spec.update(deepcopy(AUTH_ARG_SPEC))
|
||||||
|
|||||||
@@ -66,6 +66,15 @@ options:
|
|||||||
- Ignored if O(wait) is not set.
|
- Ignored if O(wait) is not set.
|
||||||
default: 120
|
default: 120
|
||||||
type: int
|
type: int
|
||||||
|
hidden_fields:
|
||||||
|
description:
|
||||||
|
- Hide fields matching this option in the result.
|
||||||
|
- An example might be O(hidden_fields=[metadata.managedFields])
|
||||||
|
or O(hidden_fields=[metadata.annotations[kubemacpool.io/transaction-timestamp]]).
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
default: ['metadata.annotations[kubemacpool.io/transaction-timestamp]', metadata.managedFields]
|
||||||
|
version_added: 2.2.0
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.9"
|
- "python >= 3.9"
|
||||||
@@ -157,7 +166,16 @@ def arg_spec():
|
|||||||
"""
|
"""
|
||||||
arg_spec defines the argument spec of this module.
|
arg_spec defines the argument spec of this module.
|
||||||
"""
|
"""
|
||||||
spec = {}
|
spec = {
|
||||||
|
"hidden_fields": {
|
||||||
|
"type": "list",
|
||||||
|
"elements": "str",
|
||||||
|
"default": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
spec.update(deepcopy(INFO_ARG_SPEC))
|
spec.update(deepcopy(INFO_ARG_SPEC))
|
||||||
spec.update(deepcopy(AUTH_ARG_SPEC))
|
spec.update(deepcopy(AUTH_ARG_SPEC))
|
||||||
|
|
||||||
|
|||||||
@@ -210,12 +210,26 @@ MODULE_PARAMS_DELETE = MODULE_PARAMS_DEFAULT | {
|
|||||||
"wait": True,
|
"wait": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MODULE_PARAMS_HIDDEN_FIELDS = MODULE_PARAMS_DEFAULT | {
|
||||||
|
"name": "testvm",
|
||||||
|
"namespace": "default",
|
||||||
|
"running": False,
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.annotations[kubectl.kubernetes.io/last-applied-configuration]",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
K8S_MODULE_PARAMS_CREATE = MODULE_PARAMS_CREATE | {
|
K8S_MODULE_PARAMS_CREATE = MODULE_PARAMS_CREATE | {
|
||||||
"generate_name": None,
|
"generate_name": None,
|
||||||
"running": None,
|
"running": None,
|
||||||
"run_strategy": None,
|
"run_strategy": None,
|
||||||
"resource_definition": VM_DEFINITION_CREATE,
|
"resource_definition": VM_DEFINITION_CREATE,
|
||||||
"wait_condition": {"type": "Ready", "status": True},
|
"wait_condition": {"type": "Ready", "status": True},
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
K8S_MODULE_PARAMS_RUNNING = MODULE_PARAMS_RUNNING | {
|
K8S_MODULE_PARAMS_RUNNING = MODULE_PARAMS_RUNNING | {
|
||||||
@@ -223,6 +237,10 @@ K8S_MODULE_PARAMS_RUNNING = MODULE_PARAMS_RUNNING | {
|
|||||||
"run_strategy": None,
|
"run_strategy": None,
|
||||||
"resource_definition": VM_DEFINITION_RUNNING,
|
"resource_definition": VM_DEFINITION_RUNNING,
|
||||||
"wait_condition": {"type": "Ready", "status": True},
|
"wait_condition": {"type": "Ready", "status": True},
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
K8S_MODULE_PARAMS_STOPPED = MODULE_PARAMS_STOPPED | {
|
K8S_MODULE_PARAMS_STOPPED = MODULE_PARAMS_STOPPED | {
|
||||||
@@ -230,6 +248,10 @@ K8S_MODULE_PARAMS_STOPPED = MODULE_PARAMS_STOPPED | {
|
|||||||
"run_strategy": None,
|
"run_strategy": None,
|
||||||
"resource_definition": VM_DEFINITION_STOPPED,
|
"resource_definition": VM_DEFINITION_STOPPED,
|
||||||
"wait_condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
"wait_condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
K8S_MODULE_PARAMS_HALTED = MODULE_PARAMS_HALTED | {
|
K8S_MODULE_PARAMS_HALTED = MODULE_PARAMS_HALTED | {
|
||||||
@@ -237,6 +259,10 @@ K8S_MODULE_PARAMS_HALTED = MODULE_PARAMS_HALTED | {
|
|||||||
"running": None,
|
"running": None,
|
||||||
"resource_definition": VM_DEFINITION_HALTED,
|
"resource_definition": VM_DEFINITION_HALTED,
|
||||||
"wait_condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
"wait_condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
K8S_MODULE_PARAMS_DELETE = MODULE_PARAMS_DELETE | {
|
K8S_MODULE_PARAMS_DELETE = MODULE_PARAMS_DELETE | {
|
||||||
@@ -245,6 +271,17 @@ K8S_MODULE_PARAMS_DELETE = MODULE_PARAMS_DELETE | {
|
|||||||
"run_strategy": None,
|
"run_strategy": None,
|
||||||
"resource_definition": VM_DEFINITION_RUNNING,
|
"resource_definition": VM_DEFINITION_RUNNING,
|
||||||
"wait_condition": {"type": "Ready", "status": True},
|
"wait_condition": {"type": "Ready", "status": True},
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
K8S_MODULE_PARAMS_HIDDEN_FIELDS = MODULE_PARAMS_HIDDEN_FIELDS | {
|
||||||
|
"generate_name": None,
|
||||||
|
"run_strategy": None,
|
||||||
|
"resource_definition": VM_DEFINITION_STOPPED,
|
||||||
|
"wait_condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -281,6 +318,12 @@ K8S_MODULE_PARAMS_DELETE = MODULE_PARAMS_DELETE | {
|
|||||||
VM_DEFINITION_RUNNING,
|
VM_DEFINITION_RUNNING,
|
||||||
"delete",
|
"delete",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
MODULE_PARAMS_HIDDEN_FIELDS,
|
||||||
|
K8S_MODULE_PARAMS_HIDDEN_FIELDS,
|
||||||
|
VM_DEFINITION_STOPPED,
|
||||||
|
"update",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_module(mocker, module_params, k8s_module_params, vm_definition, method):
|
def test_module(mocker, module_params, k8s_module_params, vm_definition, method):
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ FIND_ARGS_DEFAULT = {
|
|||||||
"wait_sleep": 5,
|
"wait_sleep": 5,
|
||||||
"wait_timeout": 120,
|
"wait_timeout": 120,
|
||||||
"condition": {"type": "Ready", "status": True},
|
"condition": {"type": "Ready", "status": True},
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
FIND_ARGS_NAME_NAMESPACE = FIND_ARGS_DEFAULT | {
|
FIND_ARGS_NAME_NAMESPACE = FIND_ARGS_DEFAULT | {
|
||||||
@@ -77,6 +81,13 @@ FIND_ARGS_STOPPED = FIND_ARGS_DEFAULT | {
|
|||||||
"condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
"condition": {"type": "Ready", "status": False, "reason": "VMINotExists"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FIND_ARGS_HIDDEN_FIELDS = FIND_ARGS_DEFAULT | {
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.annotations[kubectl.kubernetes.io/last-applied-configuration]",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"module_args,find_args",
|
"module_args,find_args",
|
||||||
@@ -87,6 +98,15 @@ FIND_ARGS_STOPPED = FIND_ARGS_DEFAULT | {
|
|||||||
({"field_selectors": "app=test"}, FIND_ARGS_FIELD_SELECTOR),
|
({"field_selectors": "app=test"}, FIND_ARGS_FIELD_SELECTOR),
|
||||||
({"wait": True, "running": True}, FIND_ARGS_RUNNING),
|
({"wait": True, "running": True}, FIND_ARGS_RUNNING),
|
||||||
({"wait": True, "running": False}, FIND_ARGS_STOPPED),
|
({"wait": True, "running": False}, FIND_ARGS_STOPPED),
|
||||||
|
(
|
||||||
|
{
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.annotations[kubectl.kubernetes.io/last-applied-configuration]",
|
||||||
|
]
|
||||||
|
},
|
||||||
|
FIND_ARGS_HIDDEN_FIELDS,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_module(mocker, module_args, find_args):
|
def test_module(mocker, module_args, find_args):
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ FIND_ARGS_DEFAULT = {
|
|||||||
"wait_sleep": 5,
|
"wait_sleep": 5,
|
||||||
"wait_timeout": 120,
|
"wait_timeout": 120,
|
||||||
"condition": {"type": "Ready", "status": True},
|
"condition": {"type": "Ready", "status": True},
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.managedFields",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
FIND_ARGS_NAME_NAMESPACE = FIND_ARGS_DEFAULT | {
|
FIND_ARGS_NAME_NAMESPACE = FIND_ARGS_DEFAULT | {
|
||||||
@@ -58,6 +62,13 @@ FIND_ARGS_FIELD_SELECTOR = FIND_ARGS_DEFAULT | {
|
|||||||
"field_selectors": ["app=test"],
|
"field_selectors": ["app=test"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FIND_ARGS_HIDDEN_FIELDS = FIND_ARGS_DEFAULT | {
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.annotations[kubectl.kubernetes.io/last-applied-configuration]",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"module_args,find_args",
|
"module_args,find_args",
|
||||||
@@ -66,6 +77,15 @@ FIND_ARGS_FIELD_SELECTOR = FIND_ARGS_DEFAULT | {
|
|||||||
({"name": "testvm", "namespace": "default"}, FIND_ARGS_NAME_NAMESPACE),
|
({"name": "testvm", "namespace": "default"}, FIND_ARGS_NAME_NAMESPACE),
|
||||||
({"label_selectors": "app=test"}, FIND_ARGS_LABEL_SELECTOR),
|
({"label_selectors": "app=test"}, FIND_ARGS_LABEL_SELECTOR),
|
||||||
({"field_selectors": "app=test"}, FIND_ARGS_FIELD_SELECTOR),
|
({"field_selectors": "app=test"}, FIND_ARGS_FIELD_SELECTOR),
|
||||||
|
(
|
||||||
|
{
|
||||||
|
"hidden_fields": [
|
||||||
|
"metadata.annotations[kubemacpool.io/transaction-timestamp]",
|
||||||
|
"metadata.annotations[kubectl.kubernetes.io/last-applied-configuration]",
|
||||||
|
]
|
||||||
|
},
|
||||||
|
FIND_ARGS_HIDDEN_FIELDS,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_module(mocker, module_args, find_args):
|
def test_module(mocker, module_args, find_args):
|
||||||
|
|||||||
Reference in New Issue
Block a user