-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update dnsmasq operator to use embeded files
This cleans up the dnsmasq controller package by moving all go templates into the dnsmasq/scripts directory.
- Loading branch information
1 parent
f9df85d
commit 3f62386
Showing
8 changed files
with
196 additions
and
169 deletions.
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,18 @@ | ||
package dnsmasq | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import _ "embed" | ||
|
||
//go:embed scripts/dnsmasq.conf.gotmpl | ||
var configFile string | ||
|
||
//go:embed scripts/dnsmasq.service.gotmpl | ||
var unitFile string | ||
|
||
//go:embed scripts/aro-dnsmasq-pre.sh.gotmpl | ||
var preScriptFile string | ||
|
||
//go:embed scripts/99-dnsmasq-restart.gotmpl | ||
var restartScript string |
45 changes: 45 additions & 0 deletions
45
pkg/operator/controllers/dnsmasq/scripts/99-dnsmasq-restart.gotmpl
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,45 @@ | ||
{{ define "99-dnsmasq-restart" }} | ||
#!/bin/sh | ||
# This is a NetworkManager dispatcher script to restart dnsmasq | ||
# in the event of a network interface change (e. g. host servicing event https://learn.microsoft.com/en-us/azure/developer/intro/hosting-apps-on-azure) | ||
# this will restart dnsmasq, reapplying our /etc/resolv.conf file and overwriting any modifications made by NetworkManager | ||
|
||
interface=$1 | ||
action=$2 | ||
|
||
log() { | ||
logger -i "$0" -t '99-DNSMASQ-RESTART SCRIPT' "$@" | ||
} | ||
|
||
# log dns configuration information relevant to SRE while troubleshooting | ||
# The line break used here is important for formatting | ||
log_dns_files() { | ||
log "/etc/resolv.conf contents | ||
|
||
$(cat /etc/resolv.conf)" | ||
|
||
log "$(echo -n \"/etc/resolv.conf file metadata: \") $(ls -lZ /etc/resolv.conf)" | ||
|
||
log "/etc/resolv.conf.dnsmasq contents | ||
|
||
$(cat /etc/resolv.conf.dnsmasq)" | ||
|
||
log "$(echo -n "/etc/resolv.conf.dnsmasq file metadata: ") $(ls -lZ /etc/resolv.conf.dnsmasq)" | ||
} | ||
|
||
if [[ $interface == eth* && $action == "up" ]] || [[ $interface == eth* && $action == "down" ]] || [[ $interface == enP* && $action == "up" ]] || [[ $interface == enP* && $action == "down" ]]; then | ||
log "$action happened on $interface, connection state is now $CONNECTIVITY_STATE" | ||
log "Pre dnsmasq restart file information" | ||
log_dns_files | ||
log "restarting dnsmasq now" | ||
if systemctl try-restart dnsmasq --wait; then | ||
log "dnsmasq successfully restarted" | ||
log "Post dnsmasq restart file information" | ||
log_dns_files | ||
else | ||
log "failed to restart dnsmasq" | ||
fi | ||
fi | ||
|
||
exit 0 | ||
{{ end }} |
Oops, something went wrong.