Wait for NM dhcp nameserver population
In some cases, the dhcp event may come before resolv.conf has nameserver
entries. In these cases, we'll wait.
@@ -22,10 +22,20 @@ contents:
# If $DHCP6_FQDN_FQDN is not empty and is not localhost.localdomain
[[ -n "$DHCP6_FQDN_FQDN" && "$DHCP6_FQDN_FQDN" != "localhost.localdomain" && "$DHCP6_FQDN_FQDN" =~ "." ]] && hostnamectl set-hostname --static --transient $DHCP6_FQDN_FQDN
case "$STATUS" in
- up|down|dhcp4-change|dhcp6-change)
- logger -s "NM resolv-prepender triggered by ${1} ${2}."
+ up|dhcp4-change|dhcp6-change)
+ >&2 echo "NM resolv-prepender triggered by ${1} ${2}."
# Ensure resolv.conf exists before we try to run podman
+ # In DHCP connections, the resolv.conf content may be late, thus we wait for nameservers
+ timeout 45s /bin/bash <<EOF
+ if [[ "$STATUS" == dhcp* ]]; then
+ >&2 echo "NM resolv-prepender: Checking for nameservers in /var/run/NetworkManager/resolv.conf"
+ while ! grep nameserver /var/run/NetworkManager/resolv.conf; do
+ >&2 echo "NM resolv-prepender: NM resolv.conf still empty of nameserver"
+ sleep 0.5
+ done
+ fi
+ EOF
cp /var/run/NetworkManager/resolv.conf /etc/resolv.conf
NAMESERVER_IP=$(/usr/bin/podman run --rm \
@@ -38,7 +48,7 @@ contents:
"{{.Infra.Status.PlatformStatus.BareMetal.IngressIP}}")
DOMAIN="{{.Infra.Status.EtcdDiscoveryDomain}}"
if [[ -n "$NAMESERVER_IP" ]]; then
- logger -s "NM resolv-prepender: Prepending 'nameserver $NAMESERVER_IP' to /etc/resolv.conf (other nameservers from /var/run/NetworkManager/resolv.conf)"
+ >&2 echo "NM resolv-prepender: Prepending 'nameserver $NAMESERVER_IP' to /etc/resolv.conf (other nameservers from /var/run/NetworkManager/resolv.conf)"
sed -e "/^search/d" \
-e "/Generated by/c# Generated by KNI resolv prepender NM dispatcher script\nsearch $DOMAIN\nnameserver $NAMESERVER_IP" \
/var/run/NetworkManager/resolv.conf > /etc/resolv.tmp
