Skip to content

Commit

Permalink
Fix duplicate prepender entries in resolv.conf
Browse files Browse the repository at this point in the history
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 88713b7)
  • Loading branch information
cybertron authored and openshift-cherrypick-robot committed Feb 25, 2022
1 parent 597b10f commit 9ee66bc
Showing 1 changed file with 1 addition and 1 deletion.
Expand Up @@ -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
Expand Down

0 comments on commit 9ee66bc

Please sign in to comment.