mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-26 21:33:02 +00:00
k8s_json_patch: support the hidden_fields param (#964)
SUMMARY Add support for hidden_fields on k8s_json_patch ISSUE TYPE Feature Pull Request COMPONENT NAME k8s_json_patch ADDITIONAL INFORMATION Works exactly the same as k8s Haven't pushed the doc yet, because of many changes. Will do it on a separate commit if the tests pass. 1st commit here, sorry if I forget some things. Thanks! Reviewed-by: Bianca Henderson <beeankha@gmail.com> Reviewed-by: Alina Buzachis Reviewed-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
committed by
GitHub
parent
cf3c3a9dcc
commit
c48778d709
@@ -33,6 +33,14 @@ options:
|
||||
aliases:
|
||||
- api
|
||||
- version
|
||||
hidden_fields:
|
||||
description:
|
||||
- List of fields to hide from the diff output.
|
||||
- This is useful for fields that are not relevant to the patch operation, such as `metadata.managedFields`.
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
version_added: 6.1.0
|
||||
kind:
|
||||
description:
|
||||
- Use to specify an object model.
|
||||
@@ -147,6 +155,7 @@ from ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions imp
|
||||
)
|
||||
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.service import (
|
||||
diff_objects,
|
||||
hide_fields,
|
||||
)
|
||||
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.waiter import (
|
||||
get_waiter,
|
||||
@@ -174,6 +183,7 @@ JSON_PATCH_ARGS = {
|
||||
"namespace": {"type": "str"},
|
||||
"name": {"type": "str", "required": True},
|
||||
"patch": {"type": "list", "required": True, "elements": "dict"},
|
||||
"hidden_fields": {"type": "list", "elements": "str", "default": []},
|
||||
}
|
||||
|
||||
|
||||
@@ -203,6 +213,7 @@ def execute_module(module, client):
|
||||
namespace = module.params.get("namespace")
|
||||
patch = module.params.get("patch")
|
||||
|
||||
hidden_fields = module.params.get("hidden_fields")
|
||||
wait = module.params.get("wait")
|
||||
wait_sleep = module.params.get("wait_sleep")
|
||||
wait_timeout = module.params.get("wait_timeout")
|
||||
@@ -260,13 +271,13 @@ def execute_module(module, client):
|
||||
module.fail_json(msg=msg, error=to_native(exc), status="", reason="")
|
||||
|
||||
success = True
|
||||
result = {"result": obj}
|
||||
result = {"result": hide_fields(obj, hidden_fields)}
|
||||
if wait and not module.check_mode:
|
||||
waiter = get_waiter(client, resource, condition=wait_condition)
|
||||
success, result["result"], result["duration"] = waiter.wait(
|
||||
wait_timeout, wait_sleep, name, namespace
|
||||
)
|
||||
match, diffs = diff_objects(existing.to_dict(), obj)
|
||||
match, diffs = diff_objects(existing.to_dict(), obj, hidden_fields)
|
||||
result["changed"] = not match
|
||||
if module._diff:
|
||||
result["diff"] = diffs
|
||||
|
||||
Reference in New Issue
Block a user