Skip to content

Commit e2f5e2b

Browse files
committed
🐛 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 a8c19c4 commit e2f5e2b

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
@@ -300,9 +300,9 @@ func New(config *rest.Config, options Options) (Manager, error) {
300300
}
301301

302302
// Create the resource lock to enable leader election)
303-
leaderConfig := config
304-
if options.LeaderElectionConfig != nil {
305-
leaderConfig = options.LeaderElectionConfig
303+
leaderConfig := options.LeaderElectionConfig
304+
if leaderConfig == nil {
305+
leaderConfig = rest.CopyConfig(config)
306306
}
307307
resourceLock, err := options.newResourceLock(leaderConfig, recorderProvider, leaderelection.Options{
308308
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)