-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from nirmata/leader-election
feat: add leader election
- Loading branch information
Showing
5 changed files
with
151 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/go-logr/logr" | ||
"github.com/kyverno/kyverno/pkg/controllers" | ||
) | ||
|
||
type Controller interface { | ||
Run(context.Context, logr.Logger, *sync.WaitGroup) | ||
} | ||
|
||
type controller struct { | ||
name string | ||
controller controllers.Controller | ||
workers int | ||
} | ||
|
||
func NewController(name string, c controllers.Controller, w int) Controller { | ||
return controller{ | ||
name: name, | ||
controller: c, | ||
workers: w, | ||
} | ||
} | ||
|
||
func (c controller) Run(ctx context.Context, logger logr.Logger, wg *sync.WaitGroup) { | ||
wg.Add(1) | ||
go func(logger logr.Logger) { | ||
logger.Info("starting controller", "workers", c.workers) | ||
defer logger.Info("controller stopped") | ||
defer wg.Done() | ||
c.controller.Run(ctx, c.workers) | ||
}(logger.WithValues("name", c.name)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters