Skip to content

Commit 7bd88f1

Browse files
Apply DNS host config on change only
1 parent 6aa4ba7 commit 7bd88f1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

client/internal/dns/server.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type DefaultServer struct {
8080
updateSerial uint64
8181
previousConfigHash uint64
8282
currentConfig HostDNSConfig
83+
currentConfigHash uint64
8384
handlerChain *HandlerChain
8485
extraDomains map[domain.Domain]int
8586

@@ -586,10 +587,28 @@ func (s *DefaultServer) applyHostConfig() {
586587

587588
log.Debugf("extra match domains: %v", maps.Keys(s.extraDomains))
588589

590+
hash, err := hashstructure.Hash(config, hashstructure.FormatV2, &hashstructure.HashOptions{
591+
ZeroNil: true,
592+
IgnoreZeroValue: true,
593+
SlicesAsSets: true,
594+
UseStringer: true,
595+
})
596+
if err != nil {
597+
log.Errorf("unable to hash the host dns configuration, got error: %s", err)
598+
return
599+
}
600+
601+
if s.currentConfigHash == hash {
602+
log.Debugf("not applying host config as there are no changes")
603+
return
604+
}
605+
589606
if err := s.hostManager.applyDNSConfig(config, s.stateManager); err != nil {
590607
log.Errorf("failed to apply DNS host manager update: %v", err)
591608
}
592609

610+
s.currentConfigHash = hash
611+
593612
s.registerFallback(config)
594613
}
595614

0 commit comments

Comments
 (0)