mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 13:32:37 +00:00
* patch only * add changelogs * Rename 89-k8s-add-parameter-patch_only.yml to 90-k8s-add-parameter-patch_only.yml * Update 90-k8s-add-parameter-patch_only.yml * patch_only parameter changed to state=patched * Update 90-k8s-add-parameter-patch_only.yml * Update plugins/modules/k8s.py Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us> * Update molecule/default/tasks/patched.yml Co-authored-by: John Mazzitelli <mazz@redhat.com> * Update molecule/default/tasks/patched.yml Co-authored-by: John Mazzitelli <mazz@redhat.com> * sanity issue Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us> Co-authored-by: John Mazzitelli <mazz@redhat.com>
124 lines
3.6 KiB
YAML
124 lines
3.6 KiB
YAML
---
|
|
- block:
|
|
- set_fact:
|
|
patch_only_namespace:
|
|
first: patched-namespace-1
|
|
second: patched-namespace-2
|
|
|
|
- name: Ensure namespace {{ patch_only_namespace.first }} exist
|
|
kubernetes.core.k8s:
|
|
definition:
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: "{{ patch_only_namespace.first }}"
|
|
labels:
|
|
existingLabel: "labelValue"
|
|
annotations:
|
|
existingAnnotation: "annotationValue"
|
|
wait: yes
|
|
|
|
- name: Ensure namespace {{ patch_only_namespace.second }} does not exist
|
|
kubernetes.core.k8s_info:
|
|
kind: namespace
|
|
name: "{{ patch_only_namespace.second }}"
|
|
register: second_namespace
|
|
|
|
- name: assert that second namespace does not exist
|
|
assert:
|
|
that:
|
|
- second_namespace.resources | length == 0
|
|
|
|
- name: apply patch on existing resource
|
|
kubernetes.core.k8s:
|
|
state: patched
|
|
wait: yes
|
|
definition: |
|
|
---
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: "{{ patch_only_namespace.first }}"
|
|
labels:
|
|
ansible: patched
|
|
---
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: "{{ patch_only_namespace.second }}"
|
|
labels:
|
|
ansible: patched
|
|
register: patch_resource
|
|
|
|
- name: assert that patch succeed
|
|
assert:
|
|
that:
|
|
- patch_resource.changed
|
|
- patch_resource.result.results | selectattr('warning', 'defined') | list | length == 1
|
|
|
|
- name: Ensure namespace {{ patch_only_namespace.first }} was patched correctly
|
|
kubernetes.core.k8s_info:
|
|
kind: namespace
|
|
name: "{{ patch_only_namespace.first }}"
|
|
register: first_namespace
|
|
|
|
- name: assert labels are as expected
|
|
assert:
|
|
that:
|
|
- first_namespace.resources[0].metadata.labels.ansible == "patched"
|
|
- first_namespace.resources[0].metadata.labels.existingLabel == "labelValue"
|
|
- first_namespace.resources[0].metadata.annotations.existingAnnotation == "annotationValue"
|
|
- name: Ensure namespace {{ patch_only_namespace.second }} was not created
|
|
kubernetes.core.k8s_info:
|
|
kind: namespace
|
|
name: "{{ patch_only_namespace.second }}"
|
|
register: second_namespace
|
|
|
|
- name: assert that second namespace does not exist
|
|
assert:
|
|
that:
|
|
- second_namespace.resources | length == 0
|
|
|
|
- name: patch all resources (create if does not exist)
|
|
kubernetes.core.k8s:
|
|
state: present
|
|
definition: |
|
|
---
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: "{{ patch_only_namespace.first }}"
|
|
labels:
|
|
patch: ansible
|
|
---
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: "{{ patch_only_namespace.second }}"
|
|
labels:
|
|
patch: ansible
|
|
wait: yes
|
|
register: patch_resource
|
|
|
|
- name: Ensure namespace {{ patch_only_namespace.second }} was created
|
|
kubernetes.core.k8s_info:
|
|
kind: namespace
|
|
name: "{{ patch_only_namespace.second }}"
|
|
register: second_namespace
|
|
|
|
- name: assert that second namespace exist
|
|
assert:
|
|
that:
|
|
- second_namespace.resources | length == 1
|
|
|
|
always:
|
|
- name: Remove namespace
|
|
kubernetes.core.k8s:
|
|
kind: Namespace
|
|
name: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- "{{ patch_only_namespace.first }}"
|
|
- "{{ patch_only_namespace.second }}"
|
|
ignore_errors: true
|