-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GCP: Prepend resolv.conf on the bootstrap node with custom-dns
When UserProvisionedDNS is enabled during an install on GCP, prepend the NetworkManager generated resolv.conf file on the bootstrap node with the IP of the localhost.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
.../data/bootstrap/gcp/files/etc/NetworkManager/dispatcher.d/30-local-dns-prepender.template
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,53 @@ | ||
#!/bin/bash | ||
IFACE=$1 | ||
STATUS=$2 | ||
case "$STATUS" in | ||
up|dhcp4-change|dhcp6-change|dns-change) | ||
{{if .PlatformData.GCP.UserProvisionedDNS}} | ||
logger -s "NM local-dns-prepender triggered by ${1} ${2}." | ||
|
||
# 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 | ||
|
||
DNS_IP="127.0.0.1" | ||
set +e | ||
if systemctl -q is-enabled systemd-resolved; then | ||
>&2 echo "NM resolv-prepender: Setting up systemd-resolved for local DNS" | ||
if [[ ! -f /etc/systemd/resolved.conf.d/60-kni.conf ]]; then | ||
>&2 echo "NM resolv-prepender: Creating /etc/systemd/resolved.conf.d/60-kni.conf" | ||
mkdir -p /etc/systemd/resolved.conf.d | ||
echo "[Resolve]" > /etc/systemd/resolved.conf.d/60-kni.conf | ||
echo "DNS=$DNS_IP" >> /etc/systemd/resolved.conf.d/60-kni.conf | ||
echo "Domains=api.{{.ClusterDomain}} api-int.{{.ClusterDomain}} apps.{{.ClusterDomain}}" >> \ | ||
/etc/systemd/resolved.conf.d/60-kni.conf | ||
if systemctl -q is-active systemd-resolved; then | ||
>&2 echo "NM resolv-prepender: restarting systemd-resolved" | ||
systemctl restart systemd-resolved | ||
fi | ||
fi | ||
else | ||
cp -f /var/run/NetworkManager/resolv.conf /etc/resolv.tmp | ||
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.tmp | ||
if cmp -s /etc/resolv.tmp /etc/resolv.conf; then | ||
logger -s "NM local-dns-prepender: /etc/resolv.conf is already up to date" | ||
rm -f /etc/resolv.tmp | ||
exit 0 | ||
|
||
else | ||
logger -s "NM local-dns-prepender: overwriting /etc/resolv.conf to add local DNS IP and DNS servers obtained by DHCP" | ||
mv -f /etc/resolv.tmp /etc/resolv.conf | ||
fi | ||
fi | ||
{{end}} | ||
;; | ||
*) | ||
;; | ||
esac |
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,21 @@ | ||
package gcp | ||
|
||
import ( | ||
"github.com/openshift/installer/pkg/types/dns" | ||
"github.com/openshift/installer/pkg/types/gcp" | ||
) | ||
|
||
// TemplateData holds data specific to templates used for the gcp platform. | ||
type TemplateData struct { | ||
// UserProvisionedDNS indicates whether this feature has been enabled on GCP | ||
UserProvisionedDNS bool | ||
} | ||
|
||
// GetTemplateData returns platform-specific data for bootstrap templates. | ||
func GetTemplateData(config *gcp.Platform) *TemplateData { | ||
var templateData TemplateData | ||
|
||
templateData.UserProvisionedDNS = (config.UserProvisionedDNS == dns.UserProvisionedDNSEnabled) | ||
|
||
return &templateData | ||
} |