mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Release lock on cancel for scheduler
This commit is contained in:
parent
5bed8d355f
commit
c5a5230d93
@ -319,12 +319,13 @@ func makeLeaderElectionConfig(config componentbaseconfig.LeaderElectionConfigura
|
||||
}
|
||||
|
||||
return &leaderelection.LeaderElectionConfig{
|
||||
Lock: rl,
|
||||
LeaseDuration: config.LeaseDuration.Duration,
|
||||
RenewDeadline: config.RenewDeadline.Duration,
|
||||
RetryPeriod: config.RetryPeriod.Duration,
|
||||
WatchDog: leaderelection.NewLeaderHealthzAdaptor(time.Second * 20),
|
||||
Name: "kube-scheduler",
|
||||
Lock: rl,
|
||||
LeaseDuration: config.LeaseDuration.Duration,
|
||||
RenewDeadline: config.RenewDeadline.Duration,
|
||||
RetryPeriod: config.RetryPeriod.Duration,
|
||||
WatchDog: leaderelection.NewLeaderHealthzAdaptor(time.Second * 20),
|
||||
Name: "kube-scheduler",
|
||||
ReleaseOnCancel: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
genericapifilters "k8s.io/apiserver/pkg/endpoints/filters"
|
||||
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/server"
|
||||
genericfilters "k8s.io/apiserver/pkg/server/filters"
|
||||
"k8s.io/apiserver/pkg/server/healthz"
|
||||
"k8s.io/apiserver/pkg/server/mux"
|
||||
@ -123,6 +124,11 @@ func runCommand(cmd *cobra.Command, opts *options.Options, registryOptions ...Op
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() {
|
||||
stopCh := server.SetupSignalHandler()
|
||||
<-stopCh
|
||||
cancel()
|
||||
}()
|
||||
|
||||
cc, sched, err := Setup(ctx, opts, registryOptions...)
|
||||
if err != nil {
|
||||
@ -202,7 +208,15 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
|
||||
sched.Run(ctx)
|
||||
},
|
||||
OnStoppedLeading: func() {
|
||||
klog.Fatalf("leaderelection lost")
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// We were asked to terminate. Exit 0.
|
||||
klog.Info("Requested to terminate. Exiting.")
|
||||
os.Exit(0)
|
||||
default:
|
||||
// We lost the lock.
|
||||
klog.Exitf("leaderelection lost")
|
||||
}
|
||||
},
|
||||
}
|
||||
leaderElector, err := leaderelection.NewLeaderElector(*cc.LeaderElection)
|
||||
|
Loading…
Reference in New Issue
Block a user