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

CON-11819 spread sync of load balancers #802

Merged
merged 6 commits into from
Feb 14, 2025
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
13 changes: 10 additions & 3 deletions cloud-controller-manager/do/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package do
import (
"context"
"fmt"
"math/rand"
"net/http"
"time"

Expand Down Expand Up @@ -71,12 +72,12 @@ func newResources(clusterID, clusterVPCID string, publicAccessFW publicAccessFir
}

type syncer interface {
Sync(name string, period time.Duration, stopCh <-chan struct{}, fn func() error)
Sync(name string, period time.Duration, initialDelay time.Duration, stopCh <-chan struct{}, fn func() error)
}

type tickerSyncer struct{}

func (s *tickerSyncer) Sync(name string, period time.Duration, stopCh <-chan struct{}, fn func() error) {
func (s *tickerSyncer) Sync(name string, period time.Duration, initialDelay time.Duration, stopCh <-chan struct{}, fn func() error) {
ticker := time.NewTicker(period)
defer ticker.Stop()

Expand All @@ -85,6 +86,12 @@ func (s *tickerSyncer) Sync(name string, period time.Duration, stopCh <-chan str
klog.Errorf("%s failed: %s", name, err)
}

select {
case <-time.After(initialDelay):
case <-stopCh:
return
}

for {
select {
case <-ticker.C:
Expand Down Expand Up @@ -126,7 +133,7 @@ func (r *ResourcesController) Run(stopCh <-chan struct{}) {
klog.Info("No cluster ID configured -- skipping cluster dependent syncers.")
return
}
go r.syncer.Sync("tags syncer", controllerSyncTagsPeriod, stopCh, r.syncTags)
go r.syncer.Sync("tags syncer", controllerSyncTagsPeriod, time.Second*time.Duration(rand.Int31n(600)), stopCh, r.syncTags)
}

// syncTags synchronizes tags. Currently, this is only needed to associate
Expand Down
4 changes: 2 additions & 2 deletions cloud-controller-manager/do/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func newRecordingSyncer(stopOn int, stopCh chan struct{}) *recordingSyncer {
}
}

func (s *recordingSyncer) Sync(name string, period time.Duration, stopCh <-chan struct{}, fn func() error) {
func (s *recordingSyncer) Sync(name string, period time.Duration, initialDelay time.Duration, stopCh <-chan struct{}, fn func() error) {
recordingFn := func() error {
s.mutex.Lock()
defer s.mutex.Unlock()
Expand All @@ -139,7 +139,7 @@ func (s *recordingSyncer) Sync(name string, period time.Duration, stopCh <-chan
return fn()
}

s.tickerSyncer.Sync(name, period, stopCh, recordingFn)
s.tickerSyncer.Sync(name, period, initialDelay, stopCh, recordingFn)
}

var (
Expand Down