mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Use context.TODO() to be explicit that cancellation is not implemented
This commit is contained in:
parent
3252beb02b
commit
102090d1f1
@ -157,11 +157,8 @@ func Run(c *cloudcontrollerconfig.CompletedConfig) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runCtx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
if !c.ComponentConfig.GenericComponent.LeaderElection.LeaderElect {
|
if !c.ComponentConfig.GenericComponent.LeaderElection.LeaderElect {
|
||||||
run(runCtx)
|
run(context.TODO())
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +184,7 @@ func Run(c *cloudcontrollerconfig.CompletedConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try and become the leader and start cloud controller manager loops
|
// Try and become the leader and start cloud controller manager loops
|
||||||
leaderelection.RunOrDie(runCtx, leaderelection.LeaderElectionConfig{
|
leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
|
||||||
Lock: rl,
|
Lock: rl,
|
||||||
LeaseDuration: c.ComponentConfig.GenericComponent.LeaderElection.LeaseDuration.Duration,
|
LeaseDuration: c.ComponentConfig.GenericComponent.LeaderElection.LeaseDuration.Duration,
|
||||||
RenewDeadline: c.ComponentConfig.GenericComponent.LeaderElection.RenewDeadline.Duration,
|
RenewDeadline: c.ComponentConfig.GenericComponent.LeaderElection.RenewDeadline.Duration,
|
||||||
|
@ -181,11 +181,8 @@ func Run(c *config.CompletedConfig) error {
|
|||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
runCtx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
if !c.ComponentConfig.GenericComponent.LeaderElection.LeaderElect {
|
if !c.ComponentConfig.GenericComponent.LeaderElection.LeaderElect {
|
||||||
run(runCtx)
|
run(context.TODO())
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +205,7 @@ func Run(c *config.CompletedConfig) error {
|
|||||||
glog.Fatalf("error creating lock: %v", err)
|
glog.Fatalf("error creating lock: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
leaderelection.RunOrDie(runCtx, leaderelection.LeaderElectionConfig{
|
leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
|
||||||
Lock: rl,
|
Lock: rl,
|
||||||
LeaseDuration: c.ComponentConfig.GenericComponent.LeaderElection.LeaseDuration.Duration,
|
LeaseDuration: c.ComponentConfig.GenericComponent.LeaderElection.LeaseDuration.Duration,
|
||||||
RenewDeadline: c.ComponentConfig.GenericComponent.LeaderElection.RenewDeadline.Duration,
|
RenewDeadline: c.ComponentConfig.GenericComponent.LeaderElection.RenewDeadline.Duration,
|
||||||
|
@ -187,14 +187,14 @@ func Run(c schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
|
|||||||
<-ctx.Done()
|
<-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()
|
defer cancel()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
cancel()
|
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)
|
return fmt.Errorf("couldn't create leader elector: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
leaderElector.Run(runCtx)
|
leaderElector.Run(ctx)
|
||||||
|
|
||||||
return fmt.Errorf("lost lease")
|
return fmt.Errorf("lost lease")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leader election is disabled, so run inline until done.
|
// Leader election is disabled, so run inline until done.
|
||||||
run(runCtx)
|
run(ctx)
|
||||||
return fmt.Errorf("finished without leader elect")
|
return fmt.Errorf("finished without leader elect")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,10 +208,9 @@ func (le *LeaderElector) renew(ctx context.Context) {
|
|||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
wait.Until(func() {
|
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.RenewDeadline)
|
||||||
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RetryPeriod+le.config.RenewDeadline)
|
|
||||||
defer timeoutCancel()
|
defer timeoutCancel()
|
||||||
err := wait.PollUntil(le.config.RetryPeriod, func() (bool, error) {
|
err := wait.PollImmediateUntil(le.config.RetryPeriod, func() (bool, error) {
|
||||||
return le.tryAcquireOrRenew(), nil
|
return le.tryAcquireOrRenew(), nil
|
||||||
}, timeoutCtx.Done())
|
}, timeoutCtx.Done())
|
||||||
le.maybeReportTransition()
|
le.maybeReportTransition()
|
||||||
|
Loading…
Reference in New Issue
Block a user