Skip to content

Commit

Permalink
Merge pull request #1144 from alvaroaleman/default-le-resourcelock
Browse files Browse the repository at this point in the history
⚠ Change leaderlock from ConfigMap to ConfigMapsLeasesResourceLock
  • Loading branch information
k8s-ci-robot committed Aug 31, 2020
2 parents efc74d0 + 87cb1aa commit 4717461
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/leaderelection/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewResourceLock(config *rest.Config, recorderProvider recorder.Provider, op
}

// TODO(JoelSpeed): switch to leaderelection object in 1.12
return resourcelock.New(resourcelock.ConfigMapsResourceLock,
return resourcelock.New(resourcelock.ConfigMapsLeasesResourceLock,
options.LeaderElectionNamespace,
options.LeaderElectionID,
client.CoreV1(),
Expand Down
18 changes: 18 additions & 0 deletions pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,24 @@ var _ = Describe("manger.Manager", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("unable to find leader election namespace: not running in-cluster, please specify LeaderElectionNamespace"))
})

// We must keep this default until we are sure all controller-runtime users have upgraded from the original default
// ConfigMap lock to a controller-runtime version that has this new default. Many users of controller-runtime skip
// versions, so we should be extremely conservative here.
It("should default to ConfigMapsLeasesResourceLock", func() {
m, err := New(cfg, Options{LeaderElection: true, LeaderElectionID: "controller-runtime", LeaderElectionNamespace: "my-ns"})
Expect(m).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
cm, ok := m.(*controllerManager)
Expect(ok).To(BeTrue())
multilock, isMultiLock := cm.resourceLock.(*resourcelock.MultiLock)
Expect(isMultiLock).To(BeTrue())
_, primaryIsConfigMapLock := multilock.Primary.(*resourcelock.ConfigMapLock)
Expect(primaryIsConfigMapLock).To(BeTrue())
_, secondaryIsLeaseLock := multilock.Secondary.(*resourcelock.LeaseLock)
Expect(secondaryIsLeaseLock).To(BeTrue())

})
})

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

0 comments on commit 4717461

Please sign in to comment.