Skip to content

Commit

Permalink
K8SPXC-1482 Add waiting period after peer list update
Browse files Browse the repository at this point in the history
This helps to avoid acting too frequently on stale DNS resolves
  • Loading branch information
s10 committed Jan 9, 2025
1 parent 191f386 commit d931f84
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/peer-list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

const (
pollPeriod = 1 * time.Second
waitPeriod = 30 * time.Second
)

var (
Expand Down Expand Up @@ -140,6 +141,10 @@ func main() {
}
newPeers := sets.NewString()
var err error

isFirstUpdate := true
lastChangeTime := time.Now()

for peers := sets.NewString(); script != ""; time.Sleep(pollPeriod) {
newPeers, err = lookup(*svc)
if err != nil {
Expand All @@ -154,9 +159,15 @@ func main() {
peerList := newPeers.List()
sort.Strings(peerList)
if strings.Join(peers.List(), ":") != strings.Join(newPeers.List(), ":") {
log.Printf("Peer list updated\nwas %v\nnow %v", peers.List(), newPeers.List())
shellOut(strings.Join(peerList, "\n"), script)
peers = newPeers
if isFirstUpdate || time.Since(lastChangeTime) >= waitPeriod {
log.Printf("Peer list updated\nwas %v\nnow %v", peers.List(), newPeers.List())
shellOut(strings.Join(peerList, "\n"), script)
peers = newPeers
lastChangeTime = time.Now()
isFirstUpdate = false
} else {
log.Printf("Ignoring peer list update, last change was %v ago", time.Since(lastChangeTime))
}
}
script = *onChange
}
Expand Down

0 comments on commit d931f84

Please sign in to comment.