Use context.TODO() to be explicit that cancellation is not implemented

This commit is contained in:
Mikhail Mazurskiy 2018-06-07 14:33:03 +10:00
parent 3252beb02b
commit 102090d1f1
No known key found for this signature in database
GPG Key ID: 93551ECC96E2F568
4 changed files with 10 additions and 17 deletions

View File

@ -157,11 +157,8 @@ func Run(c *cloudcontrollerconfig.CompletedConfig) error {
}
}
runCtx, cancel := context.WithCancel(context.Background())
defer cancel()
if !c.ComponentConfig.GenericComponent.LeaderElection.LeaderElect {
run(runCtx)
run(context.TODO())
panic("unreachable")
}
@ -187,7 +184,7 @@ func Run(c *cloudcontrollerconfig.CompletedConfig) error {
}
// Try and become the leader and start cloud controller manager loops
leaderelection.RunOrDie(runCtx, leaderelection.LeaderElectionConfig{
leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
Lock: rl,
LeaseDuration: c.ComponentConfig.GenericComponent.LeaderElection.LeaseDuration.Duration,
RenewDeadline: c.ComponentConfig.GenericComponent.LeaderElection.RenewDeadline.Duration,

View File

@ -181,11 +181,8 @@ func Run(c *config.CompletedConfig) error {
select {}
}
runCtx, cancel := context.WithCancel(context.Background())
defer cancel()
if !c.ComponentConfig.GenericComponent.LeaderElection.LeaderElect {
run(runCtx)
run(context.TODO())
panic("unreachable")
}
@ -208,7 +205,7 @@ func Run(c *config.CompletedConfig) error {
glog.Fatalf("error creating lock: %v", err)
}
leaderelection.RunOrDie(runCtx, leaderelection.LeaderElectionConfig{
leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
Lock: rl,
LeaseDuration: c.ComponentConfig.GenericComponent.LeaderElection.LeaseDuration.Duration,
RenewDeadline: c.ComponentConfig.GenericComponent.LeaderElection.RenewDeadline.Duration,

View File

@ -187,14 +187,14 @@ func Run(c schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
<-ctx.Done()
}
runCtx, cancel := context.WithCancel(context.TODO()) // once Run() accepts a context, it should be used here
ctx, cancel := context.WithCancel(context.TODO()) // TODO once Run() accepts a context, it should be used here
defer cancel()
go func() {
select {
case <-stopCh:
cancel()
case <-runCtx.Done():
case <-ctx.Done():
}
}()
@ -211,13 +211,13 @@ func Run(c schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
return fmt.Errorf("couldn't create leader elector: %v", err)
}
leaderElector.Run(runCtx)
leaderElector.Run(ctx)
return fmt.Errorf("lost lease")
}
// Leader election is disabled, so run inline until done.
run(runCtx)
run(ctx)
return fmt.Errorf("finished without leader elect")
}

View File

@ -208,10 +208,9 @@ func (le *LeaderElector) renew(ctx context.Context) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
wait.Until(func() {
// PollUntil() sleeps for "interval" duration before calling the function so we need to increase the timeout by le.config.RetryPeriod
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RetryPeriod+le.config.RenewDeadline)
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RenewDeadline)
defer timeoutCancel()
err := wait.PollUntil(le.config.RetryPeriod, func() (bool, error) {
err := wait.PollImmediateUntil(le.config.RetryPeriod, func() (bool, error) {
return le.tryAcquireOrRenew(), nil
}, timeoutCtx.Done())
le.maybeReportTransition()