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

K8SPXC-1482: Add waiting period after peer list update #1854

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading