Skip to content

Commit

Permalink
Move RunE code under Run
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Nov 12, 2024
1 parent 269f16c commit fb4b874
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions cmd/descheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,11 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
return err
}

ctx, done := signal.NotifyContext(cmd.Context(), syscall.SIGINT, syscall.SIGTERM)

pathRecorderMux := mux.NewPathRecorderMux("descheduler")
if !s.DisableMetrics {
pathRecorderMux.Handle("/metrics", legacyregistry.HandlerWithReset())
}

healthz.InstallHandler(pathRecorderMux, healthz.NamedCheck("Descheduler", healthz.PingHealthz.Check))

stoppedCh, _, err := s.SecureServingInfo.Serve(pathRecorderMux, 0, ctx.Done())
if err != nil {
klog.Fatalf("failed to start secure server: %v", err)
return err
}

if err = Run(ctx, s); err != nil {
klog.ErrorS(err, "descheduler server")
if err = Run(cmd.Context(), s); err != nil {
klog.ErrorS(err, "failed to run descheduler server")
return err
}

done()
// wait for metrics server to close
<-stoppedCh

return nil
},
}
Expand All @@ -107,8 +88,23 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
return cmd
}

func Run(ctx context.Context, rs *options.DeschedulerServer) error {
err := tracing.NewTracerProvider(ctx, rs.Tracing.CollectorEndpoint, rs.Tracing.TransportCert, rs.Tracing.ServiceName, rs.Tracing.ServiceNamespace, rs.Tracing.SampleRate, rs.Tracing.FallbackToNoOpProviderOnError)
func Run(rootCtx context.Context, rs *options.DeschedulerServer) error {
ctx, done := signal.NotifyContext(rootCtx, syscall.SIGINT, syscall.SIGTERM)

pathRecorderMux := mux.NewPathRecorderMux("descheduler")
if !rs.DisableMetrics {
pathRecorderMux.Handle("/metrics", legacyregistry.HandlerWithReset())
}

healthz.InstallHandler(pathRecorderMux, healthz.NamedCheck("Descheduler", healthz.PingHealthz.Check))

stoppedCh, _, err := rs.SecureServingInfo.Serve(pathRecorderMux, 0, ctx.Done())
if err != nil {
klog.Fatalf("failed to start secure server: %v", err)
return err
}

err = tracing.NewTracerProvider(ctx, rs.Tracing.CollectorEndpoint, rs.Tracing.TransportCert, rs.Tracing.ServiceName, rs.Tracing.ServiceNamespace, rs.Tracing.SampleRate, rs.Tracing.FallbackToNoOpProviderOnError)
if err != nil {
klog.ErrorS(err, "failed to create tracer provider")
}
Expand All @@ -117,5 +113,14 @@ func Run(ctx context.Context, rs *options.DeschedulerServer) error {
// increase the fake watch channel so the dry-run mode can be run
// over a cluster with thousands of pods
watch.DefaultChanSize = 100000
return descheduler.Run(ctx, rs)
err = descheduler.Run(ctx, rs)
if err != nil {
return err
}

done()
// wait for metrics server to close
<-stoppedCh

return nil
}

0 comments on commit fb4b874

Please sign in to comment.