generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend hidden_fields to allow more complicated field definitions
This allows us to ignore e.g. the last-applied-configuration annotation by specifying `metadata.annotations[kubectl.kubernetes.io/last-applied-configuration]`
- Loading branch information
1 parent
9e9962b
commit 0a9b5c7
Showing
6 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.service import ( | ||
hide_fields, | ||
) | ||
|
||
tests = [ | ||
dict( | ||
output=dict( | ||
kind="ConfigMap", metadata=dict(name="foo"), data=dict(one="1", two="2") | ||
), | ||
hide_fields=["metadata"], | ||
expected=dict(kind="ConfigMap", data=dict(one="1", two="2")), | ||
), | ||
dict( | ||
output=dict( | ||
kind="ConfigMap", | ||
metadata=dict( | ||
name="foo", | ||
annotations={ | ||
"kubectl.kubernetes.io/last-applied-configuration": '{"testvalue"}' | ||
}, | ||
), | ||
data=dict(one="1", two="2"), | ||
), | ||
hide_fields=[ | ||
"metadata.annotations[kubectl.kubernetes.io/last-applied-configuration]", | ||
"data.one", | ||
], | ||
expected=dict(kind="ConfigMap", metadata=dict(name="foo"), data=dict(two="2")), | ||
), | ||
dict( | ||
output=dict( | ||
kind="Pod", | ||
metadata=dict(name="foo"), | ||
spec=dict( | ||
containers=[ | ||
dict( | ||
name="containers", | ||
image="busybox", | ||
env=[ | ||
dict(name="ENV1", value="env1"), | ||
dict(name="ENV2", value="env2"), | ||
dict(name="ENV3", value="env3"), | ||
], | ||
) | ||
] | ||
), | ||
), | ||
hide_fields=["spec.containers[0].env[1].value"], | ||
expected=dict( | ||
kind="Pod", | ||
metadata=dict(name="foo"), | ||
spec=dict( | ||
containers=[ | ||
dict( | ||
name="containers", | ||
image="busybox", | ||
env=[ | ||
dict(name="ENV1", value="env1"), | ||
dict(name="ENV2"), | ||
dict(name="ENV3", value="env3"), | ||
], | ||
) | ||
] | ||
), | ||
), | ||
), | ||
] | ||
|
||
|
||
def test_hide_fields(): | ||
for test in tests: | ||
if hide_fields(test["output"], test["hide_fields"]) != test["expected"]: | ||
print(test["output"]) | ||
print(hide_fields(test["output"], test["hide_fields"])) | ||
print(test["expected"]) | ||
assert hide_fields(test["output"], test["hide_fields"]) == test["expected"] |