@@ -194,6 +194,12 @@ type Options struct {
194194 // LeaseDuration time first.
195195 LeaderElectionReleaseOnCancel bool
196196
197+ // LeaderElectionResourceLockInterface allows to provide a custom resourcelock.Interface that was created outside
198+ // of the controller-runtime. If this value is set the options LeaderElectionID, LeaderElectionNamespace,
199+ // LeaderElectionResourceLock, LeaseDuration, RenewDeadline and RetryPeriod will be ignored. This can be useful if you
200+ // want to use a locking mechanism that is currently not supported, like a MultiLock across two Kubernetes clusters.
201+ LeaderElectionResourceLockInterface resourcelock.Interface
202+
197203 // LeaseDuration is the duration that non-leader candidates will
198204 // wait to force acquire leadership. This is measured against time of
199205 // last observed ack. Default is 15 seconds.
@@ -381,14 +387,19 @@ func New(config *rest.Config, options Options) (Manager, error) {
381387 }
382388 }
383389
384- resourceLock , err := options .newResourceLock (leaderConfig , leaderRecorderProvider , leaderelection.Options {
385- LeaderElection : options .LeaderElection ,
386- LeaderElectionResourceLock : options .LeaderElectionResourceLock ,
387- LeaderElectionID : options .LeaderElectionID ,
388- LeaderElectionNamespace : options .LeaderElectionNamespace ,
389- })
390- if err != nil {
391- return nil , err
390+ var resourceLock resourcelock.Interface
391+ if options .LeaderElectionResourceLockInterface != nil && options .LeaderElection {
392+ resourceLock = options .LeaderElectionResourceLockInterface
393+ } else {
394+ resourceLock , err = options .newResourceLock (leaderConfig , leaderRecorderProvider , leaderelection.Options {
395+ LeaderElection : options .LeaderElection ,
396+ LeaderElectionResourceLock : options .LeaderElectionResourceLock ,
397+ LeaderElectionID : options .LeaderElectionID ,
398+ LeaderElectionNamespace : options .LeaderElectionNamespace ,
399+ })
400+ if err != nil {
401+ return nil , err
402+ }
392403 }
393404
394405 // Create the metrics listener. This will throw an error if the metrics bind
0 commit comments