Avoid empty "supersede domain-name-servers" directives for dhclient.conf (#10948)

Fixes https://github.com/kubernetes-sigs/kubespray/issues/10947

This patch aims to be minimal and intentionally:

- does not change the generation logic for `supersede_domain` and `supersede_search`
- does not change how `nameserverentries` (for NetworkManager) is built

It seems like `nameserverentries` in the "Generate nameservers for resolvconf, including cluster DNS"
task is built the same way as `dhclient_supersede_nameserver_entries_list`.
However, `nameserverentries` in the "Generate nameservers for resolvconf, not including cluster DNS"
task (below) is built differently for some reason. It includes `configured_nameservers` as well.
Due to these differences, I have refrained from reusing the same building logic
(`dhclient_supersede_nameserver_entries_list`) for both.

If the `configured_nameservers` addition can be removed or made to apply
to dhclient as well, we could potentially build a single list and then
generate the `nameserverentries` and `supersede_nameserver` strings from it.
pull/11421/head
Slavi Pantaleev 2024-08-06 13:38:51 +03:00 committed by GitHub
parent 5f18fe739e
commit cc03ca62be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View File

@ -185,8 +185,8 @@
set_fact: set_fact:
nameserverentries: |- nameserverentries: |-
{{ (([nodelocaldns_ip] if enable_nodelocaldns else []) + (coredns_server | d([]) if not enable_nodelocaldns else []) + nameservers | d([]) + cloud_resolver | d([]) + (configured_nameservers | d([]) if not disable_host_nameservers | d() | bool else [])) | unique | join(',') }} {{ (([nodelocaldns_ip] if enable_nodelocaldns else []) + (coredns_server | d([]) if not enable_nodelocaldns else []) + nameservers | d([]) + cloud_resolver | d([]) + (configured_nameservers | d([]) if not disable_host_nameservers | d() | bool else [])) | unique | join(',') }}
supersede_nameserver: dhclient_supersede_nameserver_entries_list: |-
supersede domain-name-servers {{ (([nodelocaldns_ip] if enable_nodelocaldns else []) + (coredns_server | d([]) if not enable_nodelocaldns else []) + nameservers | d([]) + cloud_resolver | d([]) + (configured_nameservers | d([]) if not disable_host_nameservers | d() | bool else [])) | unique | join(', ') }}; {{ (([nodelocaldns_ip] if enable_nodelocaldns else []) + (coredns_server | d([]) if not enable_nodelocaldns else []) + nameservers | d([]) + cloud_resolver | d([]) + (configured_nameservers | d([]) if not disable_host_nameservers | d() | bool else [])) | unique }}
when: not dns_early or dns_late when: not dns_early or dns_late
# This task should run instead of the above task when cluster/nodelocal DNS hasn't # This task should run instead of the above task when cluster/nodelocal DNS hasn't
@ -195,10 +195,17 @@
set_fact: set_fact:
nameserverentries: |- nameserverentries: |-
{{ (nameservers | d([]) + cloud_resolver | d([]) + configured_nameservers | d([])) | unique | join(',') }} {{ (nameservers | d([]) + cloud_resolver | d([]) + configured_nameservers | d([])) | unique | join(',') }}
supersede_nameserver: dhclient_supersede_nameserver_entries_list: |-
supersede domain-name-servers {{ (nameservers | d([]) + cloud_resolver | d([])) | unique | join(', ') }}; {{ (nameservers | d([]) + cloud_resolver | d([])) | unique }}
when: dns_early and not dns_late when: dns_early and not dns_late
- name: Generate supersede_nameserver from dhclient_supersede_nameserver_entries_list
set_fact:
supersede_nameserver: |-
{%- if dhclient_supersede_nameserver_entries_list | length > 0 -%}
supersede domain-name-servers {{ dhclient_supersede_nameserver_entries_list | join(', ') }};
{%- endif -%}
- name: Set etcd vars if using kubeadm mode - name: Set etcd vars if using kubeadm mode
set_fact: set_fact:
etcd_cert_dir: "{{ kube_cert_dir }}" etcd_cert_dir: "{{ kube_cert_dir }}"

View File

@ -2,7 +2,7 @@
- name: Configure dhclient to supersede search/domain/nameservers - name: Configure dhclient to supersede search/domain/nameservers
blockinfile: blockinfile:
block: |- block: |-
{% for item in [supersede_domain, supersede_search, supersede_nameserver] -%} {% for item in [supersede_domain, supersede_search, supersede_nameserver] | reject('equalto', '') -%}
{{ item }} {{ item }}
{% endfor %} {% endfor %}
path: "{{ dhclientconffile }}" path: "{{ dhclientconffile }}"