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

🐛 Use leader config for election events #1803

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions pkg/manager/manager.go
Expand Up @@ -335,11 +335,21 @@ func New(config *rest.Config, options Options) (Manager, error) {
}

// Create the resource lock to enable leader election)
leaderConfig := options.LeaderElectionConfig
if leaderConfig == nil {
var leaderConfig *rest.Config
var leaderRecorderProvider *intrec.Provider

if options.LeaderElectionConfig == nil {
leaderConfig = rest.CopyConfig(config)
leaderRecorderProvider = recorderProvider
} else {
leaderConfig = rest.CopyConfig(options.LeaderElectionConfig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config is a pointer to a *rest.Config. We set some fields down the line for User-Agent and similiar which means we manipulate the value behind the pointer, so it appears in the original config, i.E.:

leCfg := GetConfig()
mgr.New(cfg, manager.Options{LeaderElectionConfig: leCfg}
// If we don't do the CopyConfig, the User-Agent in the leCfg got changed

leaderRecorderProvider, err = options.newRecorderProvider(leaderConfig, cluster.GetScheme(), options.Logger.WithName("events"), options.makeBroadcaster)
if err != nil {
return nil, err
}
}
resourceLock, err := options.newResourceLock(leaderConfig, recorderProvider, leaderelection.Options{

resourceLock, err := options.newResourceLock(leaderConfig, leaderRecorderProvider, leaderelection.Options{
LeaderElection: options.LeaderElection,
LeaderElectionResourceLock: options.LeaderElectionResourceLock,
LeaderElectionID: options.LeaderElectionID,
Expand Down