1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 05:14:13 +01:00

Merge pull request #700 from jklaw90/root-ctx

Use the root context cancellation
This commit is contained in:
Kubernetes Prow Robot
2022-01-27 05:08:25 -08:00
committed by GitHub
2 changed files with 14 additions and 6 deletions

View File

@@ -20,6 +20,9 @@ package app
import (
"context"
"io"
"os/signal"
"syscall"
"k8s.io/apiserver/pkg/server/healthz"
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
@@ -69,7 +72,8 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
klog.SetLogger(log)
}
ctx := context.TODO()
ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer done()
pathRecorderMux := mux.NewPathRecorderMux("descheduler")
if !s.DisableMetrics {
pathRecorderMux.Handle("/metrics", legacyregistry.HandlerWithReset())
@@ -82,7 +86,7 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
return
}
err := Run(s)
err := Run(ctx, s)
if err != nil {
klog.ErrorS(err, "descheduler server")
}
@@ -94,6 +98,6 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
return cmd
}
func Run(rs *options.DeschedulerServer) error {
return descheduler.Run(rs)
func Run(ctx context.Context, rs *options.DeschedulerServer) error {
return descheduler.Run(ctx, rs)
}

View File

@@ -47,10 +47,9 @@ import (
"sigs.k8s.io/descheduler/pkg/descheduler/strategies/nodeutilization"
)
func Run(rs *options.DeschedulerServer) error {
func Run(ctx context.Context, rs *options.DeschedulerServer) error {
metrics.Register()
ctx := context.Background()
rsclient, err := client.CreateClient(rs.KubeconfigFile)
if err != nil {
return err
@@ -70,7 +69,12 @@ func Run(rs *options.DeschedulerServer) error {
return err
}
// tie in root ctx with our wait stopChannel
stopChannel := make(chan struct{})
go func() {
<-ctx.Done()
close(stopChannel)
}()
return RunDeschedulerStrategies(ctx, rs, deschedulerPolicy, evictionPolicyGroupVersion, stopChannel)
}