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