Skip to content

Commit

Permalink
fix: set leaderelection's ctx that can sense signal in controller
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool committed Jun 30, 2023
1 parent 9427174 commit e7ffd2b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/controller-manager/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"volcano.sh/volcano/pkg/controllers/framework"
"volcano.sh/volcano/pkg/controllers/job"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/signals"
)

const (
Expand All @@ -65,8 +66,10 @@ func Run(opt *options.ServerOption) error {

run := startControllers(config, opt)

ctx := signals.SetupSignalContext()

if !opt.EnableLeaderElection {
run(context.TODO())
run(ctx)
return fmt.Errorf("finished without leader elect")
}

Expand Down Expand Up @@ -100,7 +103,7 @@ func Run(opt *options.ServerOption) error {
return fmt.Errorf("couldn't create resource lock: %v", err)
}

leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
leaderelection.RunOrDie(ctx, leaderelection.LeaderElectionConfig{
Lock: rl,
LeaseDuration: leaseDuration,
RenewDeadline: renewDeadline,
Expand Down

0 comments on commit e7ffd2b

Please sign in to comment.