Skip to content

Commit 6afad86

Browse files
alvaroalemanRainbowMango
authored andcommitted
🐛 Manager leader election: Don't reset restcfg UserAgent
In pkg.LeaderElection.NewResourceLock we call rest.AddUserAgent which resets the restcfgs useragent and sets it to the default one plus a suffix. This resets whatever was originally set as UserAgent and since we do not copy our restcfg before passing it in there, this leads to the UserAgent being set to the leader-election one globally.
1 parent 61a5af9 commit 6afad86

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pkg/manager/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ func New(config *rest.Config, options Options) (Manager, error) {
308308
}
309309

310310
// Create the resource lock to enable leader election)
311-
leaderConfig := config
312-
if options.LeaderElectionConfig != nil {
313-
leaderConfig = options.LeaderElectionConfig
311+
leaderConfig := options.LeaderElectionConfig
312+
if leaderConfig == nil {
313+
leaderConfig = rest.CopyConfig(config)
314314
}
315315
resourceLock, err := options.newResourceLock(leaderConfig, recorderProvider, leaderelection.Options{
316316
LeaderElection: options.LeaderElection,

pkg/manager/manager_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,20 @@ var _ = Describe("manger.Manager", func() {
592592
close(done)
593593
})
594594

595+
It("should not manipulate the provided config", func() {
596+
originalCfg := rest.CopyConfig(cfg)
597+
// The options object is shared by multiple tests, copy it
598+
// into our scope so we manipulate it for this testcase only
599+
options := options
600+
options.newResourceLock = nil
601+
m, err := New(cfg, options)
602+
Expect(err).NotTo(HaveOccurred())
603+
for _, cb := range callbacks {
604+
cb(m)
605+
}
606+
Expect(m.GetConfig()).To(Equal(originalCfg))
607+
})
608+
595609
It("should stop when context is cancelled", func(done Done) {
596610
m, err := New(cfg, options)
597611
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)