Skip to content

⚠ Change leaderlock from ConfigMap to ConfigMapsLeasesResourceLock #1144

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +306 to +307
Copy link
Member

Choose a reason for hiding this comment

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

How are we going to track this for all our users? We could maybe say that v0.7.x is going to be the last release to default to ConfigMap locks, and going forward there is going to be a breaking change that user need to take into account.

The change can be part of upgrading and should be very explicit in release notes.

Copy link
Member Author

@alvaroaleman alvaroaleman Aug 31, 2020

Choose a reason for hiding this comment

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

The MultiLock we set up requires both a ConfigMap and a Lease. It is intended for transitions. I would like to start using this ASAP (so in v0.7, not later), because we will have to default to this for a very long time, until we are sure everyone had a c-r release that had the MultiLock. Othewise we can break users in a subtile way if their controller suddenly used a Lease but not a ConfigMap anymore, resulting in two leaders existing at the same time.

We also want to allow ppl to explicitly configure a different strategy if they know that all their users had a release with the MultiLock. However the default here has to be like this for a long time (certainly more than release, I would say at least a year after the first c-r release that has this change).

// 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