Skip to content

Commit 87cb1aa

Browse files
committed
⚠ Change leaderlock from ConfigMap to ConfigMapsLeasesResourceLock
This commit changes the leaderlock to ConfigMapsLeasesResourceLock, which is intended to transition ppl from the ConfigMap to the more modern Leases. It is breaking because additional RBAC is required.
1 parent be59d64 commit 87cb1aa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/leaderelection/leader_election.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func NewResourceLock(config *rest.Config, recorderProvider recorder.Provider, op
8181
}
8282

8383
// TODO(JoelSpeed): switch to leaderelection object in 1.12
84-
return resourcelock.New(resourcelock.ConfigMapsResourceLock,
84+
return resourcelock.New(resourcelock.ConfigMapsLeasesResourceLock,
8585
options.LeaderElectionNamespace,
8686
options.LeaderElectionID,
8787
client.CoreV1(),

pkg/manager/manager_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,24 @@ var _ = Describe("manger.Manager", func() {
302302
Expect(err).To(HaveOccurred())
303303
Expect(err.Error()).To(ContainSubstring("unable to find leader election namespace: not running in-cluster, please specify LeaderElectionNamespace"))
304304
})
305+
306+
// We must keep this default until we are sure all controller-runtime users have upgraded from the original default
307+
// ConfigMap lock to a controller-runtime version that has this new default. Many users of controller-runtime skip
308+
// versions, so we should be extremely conservative here.
309+
It("should default to ConfigMapsLeasesResourceLock", func() {
310+
m, err := New(cfg, Options{LeaderElection: true, LeaderElectionID: "controller-runtime", LeaderElectionNamespace: "my-ns"})
311+
Expect(m).ToNot(BeNil())
312+
Expect(err).ToNot(HaveOccurred())
313+
cm, ok := m.(*controllerManager)
314+
Expect(ok).To(BeTrue())
315+
multilock, isMultiLock := cm.resourceLock.(*resourcelock.MultiLock)
316+
Expect(isMultiLock).To(BeTrue())
317+
_, primaryIsConfigMapLock := multilock.Primary.(*resourcelock.ConfigMapLock)
318+
Expect(primaryIsConfigMapLock).To(BeTrue())
319+
_, secondaryIsLeaseLock := multilock.Secondary.(*resourcelock.LeaseLock)
320+
Expect(secondaryIsLeaseLock).To(BeTrue())
321+
322+
})
305323
})
306324

307325
It("should create a listener for the metrics if a valid address is provided", func() {

0 commit comments

Comments
 (0)