From 9ee66bc7794dacf130de2e3e0949754ec8e2ac1a Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 11 Jan 2022 16:08:30 -0600 Subject: [PATCH] Fix duplicate prepender entries in resolv.conf In #2835, we changed how the prepender finds the location to insert the prepended nameserver. Unfortunately, this caused it to prepend the nameserver before each existing nameserver line, which results in duplicate entries for the local nameserver. For example: search ostest.test.metalkube.org nameserver 192.168.111.23 nameserver 8.8.8.8 nameserver 192.168.111.23 This is mildly problematic since it pushes the second nameserver out of the list of 3 that are allowed. In general this probably won't cause problems because only the local nameserver is actually used, but it looks weird and will almost certainly result in a bug report from customers at some point. The replacement sed line is stolen from [0] and is specific to GNU sed, but that shouldn't be a problem for us since we only use that version of sed. 0: https://stackoverflow.com/questions/9970124/sed-to-insert-on-first-match-only (cherry picked from commit 88713b784a77f0a17ef61ea815f3817fcc294dfc) --- .../common/on-prem/files/NetworkManager-resolv-prepender.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/common/on-prem/files/NetworkManager-resolv-prepender.yaml b/templates/common/on-prem/files/NetworkManager-resolv-prepender.yaml index f704bd6ec3..0dc74b2755 100644 --- a/templates/common/on-prem/files/NetworkManager-resolv-prepender.yaml +++ b/templates/common/on-prem/files/NetworkManager-resolv-prepender.yaml @@ -68,7 +68,7 @@ contents: >&2 echo "NM resolv-prepender: Prepending 'nameserver $NAMESERVER_IP' to /etc/resolv.conf (other nameservers from /var/run/NetworkManager/resolv.conf)" sed -e "/Generated by/c# Generated by KNI resolv prepender NM dispatcher script" \ /var/run/NetworkManager/resolv.conf > /etc/resolv.tmp - sed -i "s/^nameserver.*/nameserver $NAMESERVER_IP\n\0/" /etc/resolv.tmp + sed -i "0,/^nameserver.*/s//nameserver $NAMESERVER_IP\n\0/" /etc/resolv.tmp # Make sure cluster domain is first in the search list sed -i "s/^search \(.*\)/search {{.DNS.Spec.BaseDomain}} \1/" /etc/resolv.tmp # Remove duplicate cluster domain entries