@@ -40,6 +40,13 @@ import (
40
40
"sigs.k8s.io/controller-runtime/pkg/webhook"
41
41
)
42
42
43
+ const (
44
+ // Values taken from: https://github.com/kubernetes/apiserver/blob/master/pkg/apis/config/v1alpha1/defaults.go
45
+ defaultLeaseDuration = 15
46
+ defaultRenewDeadline = 10
47
+ defaultRetryPeriod = 2
48
+ )
49
+
43
50
var log = logf .RuntimeLog .WithName ("manager" )
44
51
45
52
type controllerManager struct {
@@ -101,6 +108,16 @@ type controllerManager struct {
101
108
host string
102
109
103
110
webhookServer * webhook.Server
111
+
112
+ // leaseDuration is the duration that non-leader candidates will
113
+ // wait to force acquire leadership.
114
+ leaseDuration time.Duration
115
+ // renewDeadline is the duration that the acting master will retry
116
+ // refreshing leadership before giving up.
117
+ renewDeadline time.Duration
118
+ // retryPeriod is the duration the LeaderElector clients should wait
119
+ // between tries of actions.
120
+ retryPeriod time.Duration
104
121
}
105
122
106
123
// Add sets dependencies on i, and adds it to the list of runnables to start.
@@ -287,12 +304,10 @@ func (cm *controllerManager) start() {
287
304
288
305
func (cm * controllerManager ) startLeaderElection () (err error ) {
289
306
l , err := leaderelection .NewLeaderElector (leaderelection.LeaderElectionConfig {
290
- Lock : cm .resourceLock ,
291
- // Values taken from: https://github.com/kubernetes/apiserver/blob/master/pkg/apis/config/v1alpha1/defaults.go
292
- // TODO(joelspeed): These timings should be configurable
293
- LeaseDuration : 15 * time .Second ,
294
- RenewDeadline : 10 * time .Second ,
295
- RetryPeriod : 2 * time .Second ,
307
+ Lock : cm .resourceLock ,
308
+ LeaseDuration : cm .leaseDuration ,
309
+ RenewDeadline : cm .renewDeadline ,
310
+ RetryPeriod : cm .retryPeriod ,
296
311
Callbacks : leaderelection.LeaderCallbacks {
297
312
OnStartedLeading : func (_ context.Context ) {
298
313
cm .start ()
0 commit comments