Skip to content
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-controller: allow configuring DNS update interval #5759

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dns-controller/cmd/dns-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func main() {
var dnsServer, dnsProviderID, gossipListen, gossipSecret, watchNamespace, metricsListen string
var gossipSeeds, zones []string
var watchIngress bool
var updateInterval int

// Be sure to get the glog flags
glog.Flush()
Expand All @@ -71,6 +72,7 @@ func main() {
flags.StringVar(&watchNamespace, "watch-namespace", "", "Limits the functionality for pods, services and ingress to specific namespace, by default all")
flag.IntVar(&route53.MaxBatchSize, "route53-batch-size", route53.MaxBatchSize, "Maximum number of operations performed per changeset batch")
flag.StringVar(&metricsListen, "metrics-listen", "", "The address on which to listen for Prometheus metrics.")
flags.IntVar(&updateInterval, "update-interval", 5, "Configure interval at which to update DNS records.")

// Trick to avoid 'logging before flag.Parse' warning
flag.CommandLine.Parse([]string{})
Expand Down Expand Up @@ -163,7 +165,7 @@ func main() {
dnsProviders = append(dnsProviders, dnsProvider)
}

dnsController, err := dns.NewDNSController(dnsProviders, zoneRules)
dnsController, err := dns.NewDNSController(dnsProviders, zoneRules, updateInterval)
if err != nil {
glog.Errorf("Error building DNS controller: %v", err)
os.Exit(1)
Expand Down
16 changes: 10 additions & 6 deletions dns-controller/pkg/dns/dnscontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type DNSController struct {

// changeCount is a change-counter, which helps us avoid computation when nothing has changed
changeCount uint64

// update loop frequency (seconds)
updateInterval time.Duration
}

// DNSController is a Context
Expand All @@ -81,16 +84,17 @@ type DNSControllerScope struct {
var _ Scope = &DNSControllerScope{}

// NewDnsController creates a DnsController
func NewDNSController(dnsProviders []dnsprovider.Interface, zoneRules *ZoneRules) (*DNSController, error) {
func NewDNSController(dnsProviders []dnsprovider.Interface, zoneRules *ZoneRules, updateInterval int) (*DNSController, error) {
dnsCache, err := newDNSCache(dnsProviders)
if err != nil {
return nil, fmt.Errorf("error initializing DNS cache: %v", err)
}

c := &DNSController{
scopes: make(map[string]*DNSControllerScope),
zoneRules: zoneRules,
dnsCache: dnsCache,
scopes: make(map[string]*DNSControllerScope),
zoneRules: zoneRules,
dnsCache: dnsCache,
updateInterval: time.Duration(updateInterval) * time.Second,
}

return c, nil
Expand All @@ -117,10 +121,10 @@ func (c *DNSController) runWatcher(stopCh <-chan struct{}) {

if err != nil {
glog.Warningf("Unexpected error in DNS controller, will retry: %v", err)
time.Sleep(10 * time.Second)
time.Sleep(2 * c.updateInterval)
} else {
// Simple debouncing; DNS servers are typically pretty slow anyway
time.Sleep(5 * time.Second)
time.Sleep(c.updateInterval)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion protokube/cmd/protokube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func run() error {
var cloud, clusterID, dnsServer, dnsProviderID, dnsInternalSuffix, gossipSecret, gossipListen string
var flagChannels, tlsCert, tlsKey, tlsCA, peerCert, peerKey, peerCA string
var etcdBackupImage, etcdBackupStore, etcdImageSource, etcdElectionTimeout, etcdHeartbeatInterval string
var dnsUpdateInterval int

flag.BoolVar(&applyTaints, "apply-taints", applyTaints, "Apply taints to nodes based on the role")
flag.BoolVar(&containerized, "containerized", containerized, "Set if we are running containerized.")
Expand All @@ -73,6 +74,7 @@ func run() error {
flag.StringVar(&clusterID, "cluster-id", clusterID, "Cluster ID")
flag.StringVar(&dnsInternalSuffix, "dns-internal-suffix", dnsInternalSuffix, "DNS suffix for internal domain names")
flag.StringVar(&dnsServer, "dns-server", dnsServer, "DNS Server")
flags.IntVar(&dnsUpdateInterval, "dns-update-interval", 5, "Configure interval at which to update DNS records.")
flag.StringVar(&flagChannels, "channels", flagChannels, "channels to install")
flag.StringVar(&gossipListen, "gossip-listen", "0.0.0.0:3999", "address:port on which to bind for gossip")
flag.StringVar(&peerCA, "peer-ca", peerCA, "Path to a file containing the peer ca in PEM format")
Expand Down Expand Up @@ -298,7 +300,7 @@ func run() error {
return fmt.Errorf("unexpected zone flags: %q", err)
}

dnsController, err = dns.NewDNSController([]dnsprovider.Interface{dnsProvider}, zoneRules)
dnsController, err = dns.NewDNSController([]dnsprovider.Interface{dnsProvider}, zoneRules, dnsUpdateInterval)
if err != nil {
return err
}
Expand Down