@@ -20,10 +20,9 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"os"
23
+ "time"
23
24
24
25
"k8s.io/apimachinery/pkg/util/uuid"
25
- coordinationv1client "k8s.io/client-go/kubernetes/typed/coordination/v1"
26
- corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
27
26
"k8s.io/client-go/rest"
28
27
"k8s.io/client-go/tools/leaderelection/resourcelock"
29
28
@@ -49,6 +48,9 @@ type Options struct {
49
48
// LeaderElectionID determines the name of the resource that leader election
50
49
// will use for holding the leader lock.
51
50
LeaderElectionID string
51
+
52
+ // RewnewDeadline is the renew deadline for this leader election client
53
+ RewnewDeadline time.Duration
52
54
}
53
55
54
56
// NewResourceLock creates a new resource lock for use in a leader election loop.
@@ -88,25 +90,17 @@ func NewResourceLock(config *rest.Config, recorderProvider recorder.Provider, op
88
90
89
91
// Construct clients for leader election
90
92
rest .AddUserAgent (config , "leader-election" )
91
- corev1Client , err := corev1client .NewForConfig (config )
92
- if err != nil {
93
- return nil , err
94
- }
95
-
96
- coordinationClient , err := coordinationv1client .NewForConfig (config )
97
- if err != nil {
98
- return nil , err
99
- }
100
93
101
- return resourcelock .New (options .LeaderElectionResourceLock ,
94
+ return resourcelock .NewFromKubeconfig (options .LeaderElectionResourceLock ,
102
95
options .LeaderElectionNamespace ,
103
96
options .LeaderElectionID ,
104
- corev1Client ,
105
- coordinationClient ,
106
97
resourcelock.ResourceLockConfig {
107
98
Identity : id ,
108
99
EventRecorder : recorderProvider .GetEventRecorderFor (id ),
109
- })
100
+ },
101
+ config ,
102
+ options .RewnewDeadline ,
103
+ )
110
104
}
111
105
112
106
func getInClusterNamespace () (string , error ) {
0 commit comments