Skip to content

Commit

Permalink
vsphere bootstrap: support systemd-resolved in NM prepender
Browse files Browse the repository at this point in the history
FCOS has switched to systemd-resolved to control nameservers, so DNS_IP should be injected correctly
  • Loading branch information
vrutkovs committed Jan 22, 2021
1 parent 2c194f0 commit 82addf8
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@ case "$STATUS" in
{{if .PlatformData.VSphere.UserProvidedVIPs}}
logger -s "NM local-dns-prepender triggered by ${1} ${2}."
DNS_IP="127.0.0.1"
RESOLV="/etc/resolv.conf"
NMRESOLV="/var/run/NetworkManager/resolv.conf"

source /etc/os-release
if [[ $NAME == "Fedora" ]]; then
RESOLV="/var/run/systemd/resolve/resolv.conf"
NMRESOLV="/var/run/systemd/resolve/resolv.conf"
fi

# In DHCP connections, the resolv.conf content may be late, thus we wait for nameservers
timeout 45s /bin/bash <<EOF
if [[ "$STATUS" == dhcp* ]]; then
logger -s "NM resolv-prepender: Checking for nameservers in /var/run/NetworkManager/resolv.conf"
while ! grep nameserver /var/run/NetworkManager/resolv.conf; do
logger -s "NM resolv-prepender: Checking for nameservers in ${NMRESOLV}"
while ! grep nameserver ${NMRESOLV}; do
logger -s "NM resolv-prepender: NM resolv.conf still empty of nameserver"
sleep 0.5
done
fi
EOF
set +e
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
if grep nameserver ${RESOLV} | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" ${RESOLV}
fi
{{end}}
;;
Expand Down

0 comments on commit 82addf8

Please sign in to comment.