diff --git a/cmd/otel-allocator/main.go b/cmd/otel-allocator/main.go index 635b454582..7c830322ea 100644 --- a/cmd/otel-allocator/main.go +++ b/cmd/otel-allocator/main.go @@ -97,10 +97,7 @@ func main() { os.Exit(1) } - srv, err := newServer(log, allocator, discoveryManager, k8sclient, cliConf.ListenAddr) - if err != nil { - setupLog.Error(err, "Can't start the server") - } + srv := newServer(log, allocator, discoveryManager, k8sclient, cliConf.ListenAddr) interrupts := make(chan os.Signal, 1) signal.Notify(interrupts, os.Interrupt, syscall.SIGTERM) @@ -128,10 +125,7 @@ func main() { if err := srv.Shutdown(ctx); err != nil { setupLog.Error(err, "Cannot shutdown the server") } - srv, err = newServer(log, allocator, discoveryManager, k8sclient, cliConf.ListenAddr) - if err != nil { - setupLog.Error(err, "Error restarting the server with new config") - } + srv = newServer(log, allocator, discoveryManager, k8sclient, cliConf.ListenAddr) go func() { if err := srv.Start(); err != http.ErrServerClosed { setupLog.Error(err, "Can't restart the server") @@ -163,7 +157,7 @@ type server struct { server *http.Server } -func newServer(log logr.Logger, allocator allocation.Allocator, discoveryManager *lbdiscovery.Manager, k8sclient *collector.Client, listenAddr *string) (*server, error) { +func newServer(log logr.Logger, allocator allocation.Allocator, discoveryManager *lbdiscovery.Manager, k8sclient *collector.Client, listenAddr *string) *server { s := &server{ logger: log, allocator: allocator, @@ -176,7 +170,7 @@ func newServer(log logr.Logger, allocator allocation.Allocator, discoveryManager router.HandleFunc("/jobs/{job_id}/targets", s.TargetsHandler).Methods("GET") router.Path("/metrics").Handler(promhttp.Handler()) s.server = &http.Server{Addr: *listenAddr, Handler: router, ReadHeaderTimeout: 90 * time.Second} - return s, nil + return s } func configureFileDiscovery(log logr.Logger, allocator allocation.Allocator, discoveryManager *lbdiscovery.Manager, ctx context.Context, cliConfig config.CLIConfig) (*collector.Client, error) {