Skip to content

Commit 2c2ca5c

Browse files
committed
Refactor aro-dnsmasq-pre.sh to not overwrite /etc/resolv.conf
1 parent 4beb491 commit 2c2ca5c

File tree

1 file changed

+17
-45
lines changed

1 file changed

+17
-45
lines changed

pkg/operator/controllers/dnsmasq/scripts/aro-dnsmasq-pre.sh.gotmpl

+17-45
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,21 @@ set -euo pipefail
88

99
# This file can be rerun and the effect is idempotent, output might change if the DHCP configuration changes
1010

11-
TMPSELFRESOLV=$(mktemp)
12-
TMPNETRESOLV=$(mktemp)
13-
14-
echo "# Generated for dnsmasq.service - should point to self" > $TMPSELFRESOLV
15-
echo "# Generated for dnsmasq.service - should contain DHCP configured DNS" > $TMPNETRESOLV
16-
17-
if nmcli device show br-ex; then
18-
echo "OVN mode - br-ex device exists"
19-
#getting DNS search strings
20-
SEARCH_RAW=$(nmcli --get IP4.DOMAIN device show br-ex)
21-
#getting DNS servers
22-
NAMESERVER_RAW=$(nmcli --get IP4.DNS device show br-ex | tr -s " | " "\n")
23-
LOCAL_IPS_RAW=$(nmcli --get IP4.ADDRESS device show br-ex)
24-
else
25-
NETDEV=$(nmcli --get device connection show --active | head -n 1) #there should be only one active device
26-
echo "OVS SDN mode - br-ex not found, using device $NETDEV"
27-
SEARCH_RAW=$(nmcli --get IP4.DOMAIN device show $NETDEV)
28-
NAMESERVER_RAW=$(nmcli --get IP4.DNS device show $NETDEV | tr -s " | " "\n")
29-
LOCAL_IPS_RAW=$(nmcli --get IP4.ADDRESS device show $NETDEV)
11+
NODEIP=$(/sbin/ip --json route get 168.63.129.16 | /bin/jq -r ".[].prefsrc")
12+
13+
if [ "$NODEIP" != "" ]; then
14+
/bin/cp -Z /etc/resolv.conf /etc/resolv.conf.dnsmasq
15+
/bin/chmod 0744 /etc/resolv.conf.dnsmasq
16+
17+
cat <<EOF | /bin/tee /etc/NetworkManager/conf.d/dns-servers.conf
18+
# Added by dnsmasq.service
19+
[global-dns-domain-*]
20+
servers=$NODEIP
21+
EOF
22+
23+
# network manager may already be running at this point.
24+
# reload to update /etc/resolv.conf with this configuration
25+
/usr/bin/nmcli general reload conf
26+
/usr/bin/nmcli general reload dns-rc
3027
fi
31-
32-
#search line
33-
echo "search $SEARCH_RAW" | tr '\n' ' ' >> $TMPNETRESOLV
34-
echo "" >> $TMPNETRESOLV
35-
echo "search $SEARCH_RAW" | tr '\n' ' ' >> $TMPSELFRESOLV
36-
echo "" >> $TMPSELFRESOLV
37-
38-
#nameservers as separate lines
39-
echo "$NAMESERVER_RAW" | while read -r line
40-
do
41-
echo "nameserver $line" >> $TMPNETRESOLV
42-
done
43-
# device IPs are returned in address/mask format
44-
echo "$LOCAL_IPS_RAW" | while read -r line
45-
do
46-
echo "nameserver $line" | cut -d'/' -f 1 >> $TMPSELFRESOLV
47-
done
48-
49-
# done, copying files to destination locations and cleaning up
50-
/bin/cp $TMPNETRESOLV /etc/resolv.conf.dnsmasq
51-
chmod 0744 /etc/resolv.conf.dnsmasq
52-
/bin/cp $TMPSELFRESOLV /etc/resolv.conf
53-
/usr/sbin/restorecon /etc/resolv.conf
54-
/bin/rm $TMPNETRESOLV
55-
/bin/rm $TMPSELFRESOLV
56-
{{ end }}
28+
{{ end }}

0 commit comments

Comments
 (0)