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

Add disabling resync on controllers #97

Merged
merged 1 commit into from
May 3, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ NOTE: Breaking release in controllers.
- Refactor metrics recorder implementation including the prometheus backend.
- Refactor internal controller queue into a decorator implementation approach.
- Remove `Delete` method from `controller.Handler` and simplify to only `Handle` method
- Add `DisableResync` flag on controller configuration to disable the resync of all resources.

## [0.8.0] - 2019-12-11

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ The solution to this problems embraces simplicity once again, and mainly is to c
- One of the type retrieval fails, the other type controller continues working (running in degradation mode).
- Flexibility, e.g leader election for the primary type, no leader election for the secondary type.

Controller config has a handy flag to disable resync (`DisableResync`), sometimes this can be useful on secondary resources.

## Compatibility matrix

| | Kubernetes <=1.9 | Kubernetes 1.10 | Kubernetes 1.11 | Kubernetes 1.12 | Kubernetes 1.13 | Kubernetes 1.14 |
Expand Down
10 changes: 9 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ type Config struct {
ResyncInterval time.Duration
// ProcessingJobRetries is the number of times the job will try to reprocess the event before returning a real error.
ProcessingJobRetries int
// DisableResync will disable resyncing, if disabled the controller only will react on event updates and resync
// all when it runs for the first time.
// This is useful for secondary resource controllers (e.g pod controller of a primary controller based on deployments).
DisableResync bool
}

func (c *Config) setDefaults() error {
Expand Down Expand Up @@ -90,6 +94,10 @@ func (c *Config) setDefaults() error {
c.ResyncInterval = 3 * time.Minute
}

if c.DisableResync {
c.ResyncInterval = 0 // 0 == resync disabled.
}

if c.ProcessingJobRetries < 0 {
c.ProcessingJobRetries = 0
}
Expand Down Expand Up @@ -149,7 +157,7 @@ func New(cfg *Config) (Controller, error) {
informer := cache.NewSharedIndexInformer(lw, nil, cfg.ResyncInterval, store)

// Set up our informer event handler.
// Objects are already in our local store. Add only keys/jobs on the queue so they can bre processed
// Objects are already in our local store. Add only keys/jobs on the queue so they can re processed
// afterwards.
informer.AddEventHandlerWithResyncPeriod(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down
18 changes: 3 additions & 15 deletions examples/controller-concurrency-handling/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
sleepMS int
intervalS int
retries int
disableResync bool
)

func initFlags() error {
Expand All @@ -38,27 +39,13 @@ func initFlags() error {
fg.IntVar(&sleepMS, "sleep-ms", 25, "The number of milliseconds to sleep on each event handling")
fg.IntVar(&intervalS, "interval-s", 45, "The number of seconds to for reconciliation loop intervals")
fg.IntVar(&retries, "retries", 3, "The number of retries in case of error")
fg.BoolVar(&disableResync, "disable-resync", false, "Disables the resync")

err := fg.Parse(os.Args[1:])
if err != nil {
return err
}

if concurrentWorkers < 1 {
concurrentWorkers = 1
}

if sleepMS < 1 {
sleepMS = 25
}

if intervalS < 1 {
intervalS = 300
}
if retries < 0 {
retries = 0
}

return nil
}

Expand Down Expand Up @@ -119,6 +106,7 @@ func run() error {
ProcessingJobRetries: retries,
ResyncInterval: time.Duration(intervalS) * time.Second,
ConcurrentWorkers: concurrentWorkers,
DisableResync: disableResync,
}
ctrl, err := controller.New(cfg)
if err != nil {
Expand Down