generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a mechanism to hide fields from output (#629)
Provide a mechanism to hide fields from output SUMMARY The k8s and k8s_info modules can be a little noisy in verbose mode, and most of that is due to managedFields. If we can provide a mechanism to hide managedFields, the output is a lot more useful. ISSUE TYPE Feature Pull Request COMPONENT NAME k8s, k8s_info ADDITIONAL INFORMATION Before ANSIBLE_COLLECTIONS_PATH=../../.. ansible -m k8s_info -a 'kind=ConfigMap name=hide-fields-cm namespace=hide-fields' localhost [WARNING]: No inventory was parsed, only implicit localhost is available localhost | SUCCESS => { "api_found": true, "changed": false, "resources": [ { "apiVersion": "v1", "data": { "another": "value", "hello": "world" }, "kind": "ConfigMap", "metadata": { "annotations": { "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"another\":\"value\",\"hello\":\"world\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"hide-fields-cm\",\"namespace\":\"hide-fields\"}}\n" }, "creationTimestamp": "2023-06-13T01:47:47Z", "managedFields": [ { "apiVersion": "v1", "fieldsType": "FieldsV1", "fieldsV1": { "f:data": { ".": {}, "f:another": {}, "f:hello": {} }, "f:metadata": { "f:annotations": { ".": {}, "f:kubectl.kubernetes.io/last-applied-configuration": {} } } }, "manager": "kubectl-client-side-apply", "operation": "Update", "time": "2023-06-13T01:47:47Z" } ], "name": "hide-fields-cm", "namespace": "hide-fields", "resourceVersion": "2557394", "uid": "f233da63-6374-4079-9825-3562c0ed123c" } } ] } After ANSIBLE_COLLECTIONS_PATH=../../.. ansible -m k8s_info -a 'kind=ConfigMap name=hide-fields-cm namespace=hide-fields hidden_fields=metadata.managedFields' localhost [WARNING]: No inventory was parsed, only implicit localhost is available localhost | SUCCESS => { "api_found": true, "changed": false, "resources": [ { "apiVersion": "v1", "data": { "another": "value", "hello": "world" }, "kind": "ConfigMap", "metadata": { "annotations": { "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"data\":{\"another\":\"value\",\"hello\":\"world\"},\"kind\":\"ConfigMap\",\"metadata\":{\"annotations\":{},\"name\":\"hide-fields-cm\",\"namespace\":\"hide-fields\"}}\n" }, "creationTimestamp": "2023-06-13T01:47:47Z", "name": "hide-fields-cm", "namespace": "hide-fields", "resourceVersion": "2557394", "uid": "f233da63-6374-4079-9825-3562c0ed123c" } } ] } Reviewed-by: Mike Graves <[email protected]> Reviewed-by: Will Thames
- Loading branch information
1 parent
9ca13c3
commit 9e9962b
Showing
11 changed files
with
195 additions
and
5 deletions.
There are no files selected for viewing
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,2 @@ | ||
minor_changes: | ||
- k8s, k8s_info - add a hidden_fields option to allow fields to be hidden in the results of k8s and k8s_info |
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,3 @@ | ||
time=59 | ||
k8s | ||
k8s_info |
12 changes: 12 additions & 0 deletions
12
tests/integration/targets/k8s_hide_fields/defaults/main.yml
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,12 @@ | ||
--- | ||
test_namespace: "hide-fields" | ||
hide_fields_namespace: "hide-fields" | ||
hide_fields_base_configmap: | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: hide-fields-cm | ||
namespace: hide-fields | ||
data: | ||
hello: world | ||
another: value |
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,2 @@ | ||
dependencies: | ||
- setup_namespace |
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,6 @@ | ||
--- | ||
- connection: local | ||
gather_facts: false | ||
hosts: localhost | ||
roles: | ||
- k8s_hide_fields |
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,5 @@ | ||
#!/usr/bin/env bash | ||
set -eux | ||
export ANSIBLE_CALLBACKS_ENABLED=profile_tasks | ||
export ANSIBLE_ROLES_PATH=../ | ||
ansible-playbook playbook.yaml "$@" |
108 changes: 108 additions & 0 deletions
108
tests/integration/targets/k8s_hide_fields/tasks/main.yml
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,108 @@ | ||
- block: | ||
- name: Creation with hidden fields should work | ||
k8s: | ||
definition: "{{ hide_fields_base_configmap}}" | ||
hidden_fields: | ||
- metadata.managedFields | ||
register: hf1 | ||
|
||
- name: Ensure hidden fields are not present | ||
assert: | ||
that: | ||
- "'managedFields' not in hf1.result['metadata']" | ||
|
||
- name: Running without hidden fields should work | ||
k8s: | ||
definition: "{{ hide_fields_base_configmap}}" | ||
|
||
- name: Running with missing hidden fields should have no effect | ||
k8s: | ||
definition: "{{ hide_fields_base_configmap}}" | ||
hidden_fields: | ||
- does.not.exist | ||
register: hf2 | ||
|
||
- name: Ensure no change with missing hidden fields | ||
assert: | ||
that: | ||
- not hf2.changed | ||
|
||
- name: Hide status and managed fields | ||
k8s: | ||
definition: "{{ hide_fields_base_configmap}}" | ||
hidden_fields: | ||
- status | ||
- metadata.managedFields | ||
register: hf3 | ||
diff: true | ||
|
||
- name: Ensure hidden fields are not present | ||
assert: | ||
that: | ||
- "'status' not in hf3.result" | ||
- "'managedFields' not in hf3.result['metadata']" | ||
|
||
- name: k8s_info works with hidden fields | ||
k8s_info: | ||
name: "{{ hide_fields_base_configmap.metadata.name }}" | ||
namespace: "{{ hide_fields_base_configmap.metadata.namespace }}" | ||
kind: ConfigMap | ||
hidden_fields: | ||
- metadata.managedFields | ||
register: hf4 | ||
|
||
- name: Ensure hidden fields are not present | ||
assert: | ||
that: | ||
- hf4.resources | length == 1 | ||
- "'managedFields' not in hf4.resources[0]['metadata']" | ||
|
||
|
||
- name: Hiding a changed field should still result in a change | ||
k8s: | ||
definition: "{{ hide_fields_base_configmap | combine({'data':{'hello':'different'}}) }}" | ||
hidden_fields: | ||
- data | ||
- metadata.managedFields | ||
register: hf5 | ||
diff: true | ||
|
||
- name: Ensure that hidden changed field changed | ||
assert: | ||
that: | ||
- hf5.changed | ||
|
||
- name: Apply works with hidden fields | ||
k8s: | ||
definition: "{{ hide_fields_base_configmap | combine({'data':{'anew':'value'}}) }}" | ||
hidden_fields: | ||
- data | ||
apply: true | ||
register: hf6 | ||
diff: true | ||
|
||
- name: Ensure that hidden changed field changed | ||
assert: | ||
that: | ||
- hf6.changed | ||
|
||
- name: Hidden field should not show up in deletion | ||
k8s: | ||
definition: "{{ hide_fields_base_configmap}}" | ||
hidden_fields: | ||
- status | ||
state: absent | ||
register: hf7 | ||
|
||
- name: Ensure hidden fields are not present | ||
assert: | ||
that: | ||
- "'status' not in hf7.result" | ||
|
||
always: | ||
- name: Remove namespace | ||
k8s: | ||
kind: Namespace | ||
name: "{{ hide_fields_namespace }}" | ||
state: absent | ||
ignore_errors: true |