@@ -37,22 +37,32 @@ type Options struct {
37
37
// starting the manager.
38
38
LeaderElection bool
39
39
40
+ // LeaderElectionResourceLock determines which resource lock to use for leader election,
41
+ // defaults to "configmapsleases".
42
+ LeaderElectionResourceLock string
43
+
40
44
// LeaderElectionNamespace determines the namespace in which the leader
41
- // election configmap will be created.
45
+ // election resource will be created.
42
46
LeaderElectionNamespace string
43
47
44
- // LeaderElectionID determines the name of the configmap that leader election
48
+ // LeaderElectionID determines the name of the resource that leader election
45
49
// will use for holding the leader lock.
46
50
LeaderElectionID string
47
51
}
48
52
49
- // NewResourceLock creates a new config map resource lock for use in a leader
50
- // election loop
53
+ // NewResourceLock creates a new resource lock for use in a leader election loop.
51
54
func NewResourceLock (config * rest.Config , recorderProvider recorder.Provider , options Options ) (resourcelock.Interface , error ) {
52
55
if ! options .LeaderElection {
53
56
return nil , nil
54
57
}
55
58
59
+ // Default resource lock to "configmapsleases". We must keep this default until we are sure all controller-runtime
60
+ // users have upgraded from the original default ConfigMap lock to a controller-runtime version that has this new
61
+ // default. Many users of controller-runtime skip versions, so we should be extremely conservative here.
62
+ if options .LeaderElectionResourceLock == "" {
63
+ options .LeaderElectionResourceLock = resourcelock .ConfigMapsLeasesResourceLock
64
+ }
65
+
56
66
// LeaderElectionID must be provided to prevent clashes
57
67
if options .LeaderElectionID == "" {
58
68
return nil , errors .New ("LeaderElectionID must be configured" )
@@ -80,8 +90,7 @@ func NewResourceLock(config *rest.Config, recorderProvider recorder.Provider, op
80
90
return nil , err
81
91
}
82
92
83
- // TODO(JoelSpeed): switch to leaderelection object in 1.12
84
- return resourcelock .New (resourcelock .ConfigMapsLeasesResourceLock ,
93
+ return resourcelock .New (options .LeaderElectionResourceLock ,
85
94
options .LeaderElectionNamespace ,
86
95
options .LeaderElectionID ,
87
96
client .CoreV1 (),
0 commit comments