mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-11-22 15:10:22 +00:00
* Handle empty template output gracefully
* Add changelog fragment for empty template output fix
* refactor: reduce cognitive complexity of ActionModule.run
Extract compound boolean condition to a variable to reduce the
cognitive complexity from 16 to the allowed maximum of 15.
* refactor: extract duplicated error handling into _fail_with_error
Replace two identical error-handling blocks in ActionModule.run() with
a shared _fail_with_error static method to address SonarQube code
duplication finding.
* refactor: reduce code duplication in action plugin and tests
Revert _fail_with_error extraction that increased duplication on new
code. Consolidate duplicate integration test tasks for conditional
template into a single looped task.
---------
(cherry picked from commit ec8942dd90)
Co-authored-by: W. H. Wang <mattwang44@gmail.com>
Co-authored-by: aubin bikouo <abikouo@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
W. H. Wang
aubin bikouo
Claude Opus 4.6
parent
b9749c94f9
commit
fd65a4f09e
@@ -238,7 +238,55 @@
|
||||
- resource.result.results | selectattr('changed') | list | length == 1
|
||||
- resource.result.results | selectattr('error', 'defined') | list | length == 1
|
||||
|
||||
- name: Apply template where all items are disabled (empty output)
|
||||
kubernetes.core.k8s:
|
||||
state: present
|
||||
template:
|
||||
path: "conditional_empty.j2"
|
||||
vars:
|
||||
items:
|
||||
- name: test1
|
||||
enabled: false
|
||||
- name: test2
|
||||
enabled: false
|
||||
k8s_pod_namespace: "{{ template_namespace }}"
|
||||
register: r
|
||||
|
||||
- name: Check that empty template succeeds with no changes
|
||||
assert:
|
||||
that:
|
||||
- r is successful
|
||||
- r is not changed
|
||||
|
||||
- name: Apply template where some items are enabled
|
||||
kubernetes.core.k8s:
|
||||
state: present
|
||||
template:
|
||||
path: "conditional_empty.j2"
|
||||
vars:
|
||||
items:
|
||||
- name: conditional-configmap-1
|
||||
enabled: true
|
||||
- name: conditional-configmap-2
|
||||
enabled: false
|
||||
k8s_pod_namespace: "{{ template_namespace }}"
|
||||
register: r
|
||||
|
||||
- name: Check that partial template creates resources
|
||||
assert:
|
||||
that:
|
||||
- r is successful
|
||||
- r is changed
|
||||
|
||||
always:
|
||||
- name: Cleanup conditional configmap
|
||||
kubernetes.core.k8s:
|
||||
state: absent
|
||||
kind: ConfigMap
|
||||
name: conditional-configmap-1
|
||||
namespace: "{{ template_namespace }}"
|
||||
ignore_errors: true
|
||||
|
||||
- name: Remove namespace (Cleanup)
|
||||
kubernetes.core.k8s:
|
||||
kind: Namespace
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{% for item in items %}
|
||||
{% if item.enabled %}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: "{{ item.name }}"
|
||||
namespace: "{{ k8s_pod_namespace }}"
|
||||
data:
|
||||
key: value
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
Reference in New Issue
Block a user