-
Notifications
You must be signed in to change notification settings - Fork 6.9k
CiliumBGPAdvertisement labels issue #13141
Description
Hi!
Issue while rendering a Kubernetes manifest template with Ansible/Jinja2 when labels is intended to be optional.
Render a CiliumBGPAdvertisement YAML where metadata.labels is included only if labels is provided in the input variable.
kubespray/roles/network_plugin/cilium/templates/cilium/cilium-bgp-advertisement.yml.j2
Line 7 in 90ce800
| {% if cilium_bgp_advertisement.labels %} |
Error
During task execution Ansible fails with:
ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'labels'
Root cause
cilium_bgp_advertisement is defined, but it doesn’t always contain the labels key. In Jinja2, the expression in the if statement (cilium_bgp_advertisement.labels) is evaluated first, and it errors out before the condition can be checked.
Expected behavior
If labels is not provided, the template should render without metadata.labels and without failing.
Suggested fix / workaround
Use a defined-check or a safe getter, e.g.:
{% if cilium_bgp_advertisement.labels is defined %}
labels:
{{ cilium_bgp_advertisement.labels | to_nice_yaml(indent=2) | indent(2) }}
{% endif %}