Skip to content

Commit

Permalink
Remove excluded controllers early to safe memory
Browse files Browse the repository at this point in the history
Rather than watching excluded controller (and just omiting them at save
time), just don't watch them, so we'll save memory (and cpu time too).
  • Loading branch information
bpineau committed Apr 1, 2018
1 parent e1b2be5 commit 8e8fcbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions pkg/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ func Register(name string, ctrl ControllerConstructor) {
AllControllers[name] = ctrl
}

// FilterControllers removes excluded controllers
func FilterControllers(excluded []string) map[string]ControllerConstructor {
filtered := make(map[string]ControllerConstructor)

for k, v := range AllControllers {
filtered[k] = v
}

for _, ctrl := range excluded {
delete(filtered, ctrl)
}

return filtered
}

// Start initialize and launch a controller. The sync.WaitGroup
// argument is expected to be aknowledged (Done()) at controller
// termination, when Stop() is called.
Expand Down
6 changes: 4 additions & 2 deletions pkg/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (

// Run launchs the effective controllers goroutines
func Run(config *config.KdnConfig) {
ctrlers := controllers.FilterControllers(config.ExcludeKind)

wg := sync.WaitGroup{}
wg.Add(len(controllers.AllControllers))
wg.Add(len(ctrlers))
defer wg.Wait()

repos := git.New(config)
Expand All @@ -31,7 +33,7 @@ func Run(config *config.KdnConfig) {

var chans []chan controllers.Event

for _, c := range controllers.AllControllers {
for _, c := range ctrlers {
ch := make(chan controllers.Event, 100)
chans = append(chans, ch)
ctrl := c(config, ch)
Expand Down

0 comments on commit 8e8fcbb

Please sign in to comment.