File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ type leaderElection struct {
60
60
renewDeadline time.Duration
61
61
retryPeriod time.Duration
62
62
63
+ ctx context.Context
64
+
63
65
clientset kubernetes.Interface
64
66
}
65
67
@@ -127,6 +129,11 @@ func (l *leaderElection) WithRetryPeriod(retryPeriod time.Duration) {
127
129
l .retryPeriod = retryPeriod
128
130
}
129
131
132
+ // WithContext Add context
133
+ func (l * leaderElection ) WithContext (ctx context.Context ) {
134
+ l .ctx = ctx
135
+ }
136
+
130
137
func (l * leaderElection ) Run () error {
131
138
if l .identity == "" {
132
139
id , err := defaultLeaderElectionIdentity ()
@@ -174,7 +181,11 @@ func (l *leaderElection) Run() error {
174
181
},
175
182
}
176
183
177
- leaderelection .RunOrDie (context .TODO (), leaderConfig )
184
+ ctx := l .ctx
185
+ if ctx == nil {
186
+ ctx = context .Background ()
187
+ }
188
+ leaderelection .RunOrDie (ctx , leaderConfig )
178
189
return nil // should never reach here
179
190
}
180
191
You can’t perform that action at this time.
0 commit comments