Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion leaderelection/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type leaderElection struct {
renewDeadline time.Duration
retryPeriod time.Duration

ctx context.Context

clientset kubernetes.Interface
}

Expand Down Expand Up @@ -127,6 +129,11 @@ func (l *leaderElection) WithRetryPeriod(retryPeriod time.Duration) {
l.retryPeriod = retryPeriod
}

// WithContext Add context
func (l *leaderElection) WithContext(ctx context.Context) {
l.ctx = ctx
}

func (l *leaderElection) Run() error {
if l.identity == "" {
id, err := defaultLeaderElectionIdentity()
Expand Down Expand Up @@ -174,7 +181,10 @@ func (l *leaderElection) Run() error {
},
}

leaderelection.RunOrDie(context.TODO(), leaderConfig)
if l.ctx == nil {
l.ctx = context.TODO()
}
leaderelection.RunOrDie(l.ctx, leaderConfig)
return nil // should never reach here
}

Expand Down