-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dns] Add support for static DNS configuration. #14549
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
591eb05
Revert "Revert "Clear DNS configuration received from DHCP during net…
oleksandrivantsiv 0ea6e3d
[dns] Add support for static DNS configuration.
oleksandrivantsiv 86d0a5d
[dns] Update containers' DNS configuration following host OS update.
oleksandrivantsiv 175dadf
[dns] Add DNS configuration support to minigraph file.
oleksandrivantsiv 98a1fff
[dns] Update /etc/resolv.conf during a service restart
oleksandrivantsiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description=Update DNS configuration | ||
Requires=updategraph.service | ||
After=updategraph.service | ||
BindsTo=sonic.target | ||
After=sonic.target | ||
StartLimitIntervalSec=0 | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/usr/bin/resolv-config.sh start | ||
|
||
[Install] | ||
WantedBy=sonic.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
WD=/var/run/resolvconf/ | ||
CONFIG_DIR=${WD}/interface/ | ||
STATIC_CONFIG_FILE=mgmt.static | ||
DYNAMIC_CONFIG_FILE_TEMPLATE=*.dhclient | ||
|
||
update_symlink() | ||
{ | ||
ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf | ||
} | ||
|
||
start() | ||
{ | ||
update_symlink | ||
|
||
redis-dump -d 4 -k "DNS_NAMESERVER*" -y > /tmp/dns.json | ||
if [[ $? -eq 0 && "$(cat /tmp/dns.json)" != "{}" ]]; then | ||
# Apply static DNS configuration and disable updates | ||
/sbin/resolvconf --disable-updates | ||
pushd ${CONFIG_DIR} | ||
# Backup dynamic configuration to restore it when the static configuration is removed | ||
mv ${DYNAMIC_CONFIG_FILE_TEMPLATE} ${WD} || true | ||
|
||
sonic-cfggen -d -t /usr/share/sonic/templates/resolv.conf.j2,${STATIC_CONFIG_FILE} | ||
|
||
/sbin/resolvconf --enable-updates | ||
/sbin/resolvconf -u | ||
/sbin/resolvconf --disable-updates | ||
popd | ||
else | ||
# Dynamic DNS configuration. Enable updates. It is expected to receive configuraution for DHCP server | ||
/sbin/resolvconf --disable-updates | ||
pushd ${CONFIG_DIR} | ||
rm -f ${STATIC_CONFIG_FILE} | ||
# Restore dynamic configuration if it exists | ||
mv ${WD}/${DYNAMIC_CONFIG_FILE_TEMPLATE} ${CONFIG_DIR} || true | ||
|
||
/sbin/resolvconf --enable-updates | ||
/sbin/resolvconf -u | ||
fi | ||
} | ||
|
||
clean-dynamic-conf() | ||
{ | ||
rm -f ${WD}/${DYNAMIC_CONFIG_FILE_TEMPLATE} | ||
rm -f ${WD}/postponed-update | ||
} | ||
|
||
case $1 in | ||
start) | ||
start | ||
;; | ||
cleanup) | ||
clean-dynamic-conf | ||
;; | ||
*) | ||
echo "Usage: $0 {start|clean-dynamic-conf}" | ||
exit 2 | ||
;; | ||
esac |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Dynamic resolv.conf(5) file generated by resolvconf(8) | ||
# The content of this file may be overwritten during a config reload. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% for ip in DNS_NAMESERVER|sort %} | ||
nameserver {{ ip }} | ||
{% endfor -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
for container in $(docker ps -a --format=" {{ .ID }}"); do | ||
docker cp -L /etc/resolv.conf ${container}:/_resolv.conf | ||
docker exec -t ${container} bash -c "cat /_resolv.conf > /etc/resolv.conf" | ||
docker exec -t ${container} bash -c "rm /_resolv.conf" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nameserver 1.1.1.1 | ||
nameserver 2001:4860:4860::8888 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"DNS_NAMESERVER": { | ||
"1.1.1.1": {}, | ||
"2001:4860:4860::8888": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some containers like telemetry will start after 3 minutes.
If we upgrade SONiC image, and start the system for the first time, can we update /etc/resolv.conf in telemetry container?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker ps -a
command returns all existing containers on the system. And we will update/etc/resolv.conf
file for all containers including those that are not running.For the case when the container is created in the runtime (for example app extension), when the dockerd starts the container it copies
/etc/resolv.conf
file from the host OS into the container filesystem. So, we will always have a valid DNS configuration inside the containers.