mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 13:32:37 +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
@@ -0,0 +1,3 @@
|
||||
k8s_json_patch
|
||||
k8s
|
||||
time=33
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
test_namespace: "k8s-hide-fields"
|
||||
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- setup_namespace
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- connection: local
|
||||
gather_facts: false
|
||||
hosts: localhost
|
||||
roles:
|
||||
- k8s_json_patch_hide_fields
|
||||
5
tests/integration/targets/k8s_json_patch_hide_fields/runme.sh
Executable file
5
tests/integration/targets/k8s_json_patch_hide_fields/runme.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eux
|
||||
export ANSIBLE_CALLBACKS_ENABLED=profile_tasks
|
||||
export ANSIBLE_ROLES_PATH=../
|
||||
ansible-playbook playbook.yaml "$@"
|
||||
@@ -0,0 +1,91 @@
|
||||
- vars:
|
||||
pod: json-patch
|
||||
k8s_wait_timeout: 400
|
||||
|
||||
block:
|
||||
- name: Create a simple pod
|
||||
kubernetes.core.k8s:
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
namespace: "{{ test_namespace }}"
|
||||
name: "{{ pod }}"
|
||||
labels:
|
||||
label1: foo
|
||||
spec:
|
||||
containers:
|
||||
- image: busybox:musl
|
||||
name: busybox
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- while true; do echo $(date); sleep 10; done
|
||||
wait: yes
|
||||
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
|
||||
|
||||
|
||||
- name: Add a label, and hide some fields
|
||||
kubernetes.core.k8s_json_patch:
|
||||
kind: Pod
|
||||
namespace: "{{ test_namespace }}"
|
||||
name: "{{ pod }}"
|
||||
patch:
|
||||
- op: add
|
||||
path: /metadata/labels/label2
|
||||
value: bar
|
||||
hidden_fields:
|
||||
- metadata.managedFields
|
||||
register: hf1
|
||||
|
||||
- name: Ensure hidden fields are not present
|
||||
assert:
|
||||
that:
|
||||
- "'managedFields' not in hf1.result['metadata']"
|
||||
|
||||
|
||||
- name: Add a label, without hiding our fields
|
||||
kubernetes.core.k8s_json_patch:
|
||||
kind: Pod
|
||||
namespace: "{{ test_namespace }}"
|
||||
name: "{{ pod }}"
|
||||
patch:
|
||||
- op: add
|
||||
path: /metadata/labels/label3
|
||||
value: bar
|
||||
hidden_fields:
|
||||
- something.else
|
||||
register: hf2
|
||||
|
||||
- name: Ensure hidden fields are present
|
||||
assert:
|
||||
that:
|
||||
- "'managedFields' in hf2.result['metadata']"
|
||||
|
||||
|
||||
- name: Patching the same resource with missing hidden fields should have no effect
|
||||
kubernetes.core.k8s_json_patch:
|
||||
kind: Pod
|
||||
namespace: "{{ test_namespace }}"
|
||||
name: "{{ pod }}"
|
||||
patch:
|
||||
- op: add
|
||||
path: /metadata/labels/label2
|
||||
value: bar
|
||||
hidden_fields:
|
||||
- does.not.exist
|
||||
register: hf2
|
||||
|
||||
- name: Ensure no change with missing hidden fields
|
||||
assert:
|
||||
that:
|
||||
- not hf2.changed
|
||||
|
||||
|
||||
always:
|
||||
- name: Remove namespace
|
||||
k8s:
|
||||
kind: Namespace
|
||||
name: "{{ test_namespace }}"
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
Reference in New Issue
Block a user