Skip to content

Commit 9fddbd0

Browse files
committed
Simplify dns management
This relies on the node service configuring dnsmasq for all the zones that the node should be responsible via dbus. This removes all install time node specific configuration as well.
1 parent fced826 commit 9fddbd0

File tree

5 files changed

+16
-87
lines changed

5 files changed

+16
-87
lines changed

roles/openshift_node/templates/node.service.j2

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ After=dnsmasq.service
1414
Type=notify
1515
EnvironmentFile=/etc/sysconfig/{{ openshift.common.service_type }}-node
1616
Environment=GOTRACEBACK=crash
17-
ExecStartPre=/usr/bin/cp /etc/origin/node/node-dnsmasq.conf /etc/dnsmasq.d/
18-
ExecStartPre=/usr/bin/dbus-send --system --dest=uk.org.thekelleys.dnsmasq /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetDomainServers array:string:/in-addr.arpa/127.0.0.1,/{{ openshift.common.dns_domain }}/127.0.0.1
19-
ExecStopPost=/usr/bin/rm /etc/dnsmasq.d/node-dnsmasq.conf
20-
ExecStopPost=/usr/bin/dbus-send --system --dest=uk.org.thekelleys.dnsmasq /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetDomainServers array:string:
2117
ExecStart=/usr/bin/openshift start node --config=${CONFIG_FILE} $OPTIONS
2218
LimitNOFILE=65536
2319
LimitCORE=infinity

roles/openshift_node_dnsmasq/files/networkmanager/99-origin-dns.sh

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# a pod would fail.
1010
#
1111
# To use this,
12-
# - If this host is also a master, reconfigure master dnsConfig to listen on
13-
# 8053 to avoid conflicts on port 53 and open port 8053 in the firewall
1412
# - Drop this script in /etc/NetworkManager/dispatcher.d/
1513
# - systemctl restart NetworkManager
1614
# - Configure node-config.yaml to set dnsIP: to the ip address of this
@@ -29,16 +27,8 @@ cd /etc/sysconfig/network-scripts
2927
[ -f ../network ] && . ../network
3028

3129
if [[ $2 =~ ^(up|dhcp4-change|dhcp6-change)$ ]]; then
32-
# If the origin-upstream-dns config file changed we need to restart
3330
NEEDS_RESTART=0
34-
UPSTREAM_DNS='/etc/dnsmasq.d/origin-upstream-dns.conf'
35-
# We'll regenerate the dnsmasq origin config in a temp file first
36-
UPSTREAM_DNS_TMP=`mktemp`
37-
UPSTREAM_DNS_TMP_SORTED=`mktemp`
38-
CURRENT_UPSTREAM_DNS_SORTED=`mktemp`
3931
NEW_RESOLV_CONF=`mktemp`
40-
NEW_NODE_RESOLV_CONF=`mktemp`
41-
4232

4333
######################################################################
4434
# couldn't find an existing method to determine if the interface owns the
@@ -49,52 +39,18 @@ if [[ $2 =~ ^(up|dhcp4-change|dhcp6-change)$ ]]; then
4939
if [[ ${DEVICE_IFACE} == ${def_route_int} ]]; then
5040
if [ ! -f /etc/dnsmasq.d/origin-dns.conf ]; then
5141
cat << EOF > /etc/dnsmasq.d/origin-dns.conf
52-
no-resolv
5342
domain-needed
54-
server=/cluster.local/172.30.0.1
55-
server=/30.172.in-addr.arpa/172.30.0.1
5643
enable-dbus
44+
bind-dynamic
45+
except-interface=lo
46+
dns-loop-detect
47+
resolv-file=/etc/origin/node/resolv.conf
5748
EOF
5849
# New config file, must restart
5950
NEEDS_RESTART=1
6051
fi
6152

62-
# If network manager doesn't know about the nameservers then the best
63-
# we can do is grab them from /etc/resolv.conf but only if we've got no
64-
# watermark
65-
if ! grep -q '99-origin-dns.sh' /etc/resolv.conf; then
66-
if [[ -z "${IP4_NAMESERVERS}" || "${IP4_NAMESERVERS}" == "${def_route_ip}" ]]; then
67-
IP4_NAMESERVERS=`grep '^nameserver ' /etc/resolv.conf | awk '{ print $2 }'`
68-
fi
69-
######################################################################
70-
# Write out default nameservers for /etc/dnsmasq.d/origin-upstream-dns.conf
71-
# and /etc/origin/node/resolv.conf in their respective formats
72-
for ns in ${IP4_NAMESERVERS}; do
73-
if [[ ! -z $ns ]]; then
74-
echo "server=${ns}" >> $UPSTREAM_DNS_TMP
75-
echo "nameserver ${ns}" >> $NEW_NODE_RESOLV_CONF
76-
fi
77-
done
78-
# Sort it in case DNS servers arrived in a different order
79-
sort $UPSTREAM_DNS_TMP > $UPSTREAM_DNS_TMP_SORTED
80-
sort $UPSTREAM_DNS > $CURRENT_UPSTREAM_DNS_SORTED
81-
# Compare to the current config file (sorted)
82-
NEW_DNS_SUM=`md5sum ${UPSTREAM_DNS_TMP_SORTED} | awk '{print $1}'`
83-
CURRENT_DNS_SUM=`md5sum ${CURRENT_UPSTREAM_DNS_SORTED} | awk '{print $1}'`
84-
if [ "${NEW_DNS_SUM}" != "${CURRENT_DNS_SUM}" ]; then
85-
# DNS has changed, copy the temp file to the proper location (-Z
86-
# sets default selinux context) and set the restart flag
87-
cp -Z $UPSTREAM_DNS_TMP $UPSTREAM_DNS
88-
NEEDS_RESTART=1
89-
fi
90-
# compare /etc/origin/node/resolv.conf checksum and replace it if different
91-
NEW_NODE_RESOLV_CONF_MD5=`md5sum ${NEW_NODE_RESOLV_CONF}`
92-
OLD_NODE_RESOLV_CONF_MD5=`md5sum /etc/origin/node/resolv.conf`
93-
if [ "${NEW_NODE_RESOLV_CONF_MD5}" != "${OLD_NODE_RESOLV_CONF_MD5}" ]; then
94-
cp -Z $NEW_NODE_RESOLV_CONF /etc/origin/node/resolv.conf
95-
fi
96-
fi
97-
53+
# dnsmasq not running, needs a restart
9854
if ! `systemctl -q is-active dnsmasq.service`; then
9955
NEEDS_RESTART=1
10056
fi
@@ -103,6 +59,10 @@ EOF
10359
if [ "${NEEDS_RESTART}" -eq "1" ]; then
10460
systemctl restart dnsmasq
10561
fi
62+
63+
if [ ! -f /etc/origin/node/resolv.conf ]; then
64+
cp /etc/resolv.conf /etc/origin/node/resolv.conf
65+
fi
10666

10767
# Only if dnsmasq is running properly make it our only nameserver and place
10868
# a watermark on /etc/resolv.conf
@@ -122,5 +82,5 @@ EOF
12282
fi
12383

12484
# Clean up after yourself
125-
rm -f $UPSTREAM_DNS_TMP $UPSTREAM_DNS_TMP_SORTED $CURRENT_UPSTREAM_DNS_SORTED $NEW_RESOLV_CONF
85+
rm -f $NEW_RESOLV_CONF
12686
fi

roles/openshift_node_dnsmasq/tasks/main.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,15 @@
1414
package: name=dnsmasq state=installed
1515
when: not openshift.common.is_atomic | bool
1616

17-
- name: ensure origin/node directory exists
17+
- name: Remove older dnsmasq configuration files
1818
file:
19-
state: directory
2019
path: "{{ item }}"
21-
owner: root
22-
group: root
23-
mode: '0700'
20+
state: absent
2421
with_items:
25-
- /etc/origin
26-
- /etc/origin/node
27-
28-
# this file is copied to /etc/dnsmasq.d/ when the node starts and is removed
29-
# when the node stops. A dbus-message is sent to dnsmasq to add the same entries
30-
# so that dnsmasq doesn't need to be restarted. Once we can use dnsmasq 2.77 or
31-
# newer we can use --server-file option to update the servers dynamically and
32-
# reload them by sending dnsmasq a SIGHUP. We write the file in case someone else
33-
# triggers a restart of dnsmasq but not a node restart.
34-
- name: Install node-dnsmasq.conf
35-
template:
36-
src: node-dnsmasq.conf.j2
37-
dest: /etc/origin/node/node-dnsmasq.conf
38-
39-
- name: Install dnsmasq configuration
40-
template:
41-
src: origin-dns.conf.j2
42-
dest: /etc/dnsmasq.d/origin-dns.conf
43-
notify: restart dnsmasq
22+
- "/etc/dnsmasq.d/origin-upstream-dns.conf"
23+
- "/etc/dnsmasq.d/node-dnsmasq.conf"
24+
- "/etc/dnsmasq.d/origin-dns.conf"
25+
when: openshift.common.version_gte_3_7 | bool
4426

4527
- name: Deploy additional dnsmasq.conf
4628
template:

roles/openshift_node_dnsmasq/templates/node-dnsmasq.conf.j2

Lines changed: 0 additions & 2 deletions
This file was deleted.

roles/openshift_node_dnsmasq/templates/origin-dns.conf.j2

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)