From 145a7942e5e09cfaf9fb09b2aab4313cffd3efb7 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Thu, 7 Nov 2024 11:24:16 +0100 Subject: [PATCH] Fix the pretty-printing of (core|nodelocal)dns When using dns_upstream_forward_extra_opts: prefer_udp: "" # the option as no value so use empty string to just # put the key This is rendered in the dns configmap as ($ for end-of-line) ... prefer_udp $ ... Note the trailing space. This triggers https://github.com/kubernetes/kubernetes/issues/36222, which makes the configmap hardly readable when editing them manually or simply putting them in a yaml file for inspection. Trim the concatenation of option + value to get rid of any trailing space. --- .../ansible/templates/coredns-config.yml.j2 | 4 +++- .../ansible/templates/nodelocaldns-config.yml.j2 | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 b/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 index 004ce0643..08f779794 100644 --- a/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 +++ b/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 @@ -70,7 +70,9 @@ data: max_concurrent 1000 {% if dns_upstream_forward_extra_opts is defined %} {% for optname, optvalue in dns_upstream_forward_extra_opts.items() %} - {{ optname }} {{ optvalue }} + {{ (optname ~ ' ' ~ optvalue) | trim }} + {# do not add a trailing space when optvalue == '' + workaround for: https://github.com/kubernetes/kubernetes/issues/36222 #} {% endfor %} {% endif %} } diff --git a/roles/kubernetes-apps/ansible/templates/nodelocaldns-config.yml.j2 b/roles/kubernetes-apps/ansible/templates/nodelocaldns-config.yml.j2 index b15ea89e9..889cfc6de 100644 --- a/roles/kubernetes-apps/ansible/templates/nodelocaldns-config.yml.j2 +++ b/roles/kubernetes-apps/ansible/templates/nodelocaldns-config.yml.j2 @@ -82,7 +82,9 @@ data: bind {{ nodelocaldns_ip }} forward . {{ upstreamForwardTarget }}{% if dns_upstream_forward_extra_opts is defined %} { {% for optname, optvalue in dns_upstream_forward_extra_opts.items() %} - {{ optname }} {{ optvalue }} + {{ (optname ~ ' ' ~ optvalue) | trim }} + {# do not add a trailing space when optvalue == '' + workaround for: https://github.com/kubernetes/kubernetes/issues/36222 #} {% endfor %} }{% endif %} @@ -164,7 +166,9 @@ data: bind {{ nodelocaldns_ip }} forward . {{ upstreamForwardTarget }}{% if dns_upstream_forward_extra_opts is defined %} { {% for optname, optvalue in dns_upstream_forward_extra_opts.items() %} - {{ optname }} {{ optvalue }} + {{ (optname ~ ' ' ~ optvalue) | trim }} + {# do not add a trailing space when optvalue == '' + workaround for: https://github.com/kubernetes/kubernetes/issues/36222 #} {% endfor %} }{% endif %}