From 696f6883b4629362532b9911bbdc660faff6d8af Mon Sep 17 00:00:00 2001 From: Aaron Schlesinger Date: Thu, 7 Oct 2021 23:16:23 +0000 Subject: [PATCH] using ServeContext for all production HTTP servers Signed-off-by: Aaron Schlesinger --- operator/main.go | 3 ++- scaler/main.go | 14 +++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/operator/main.go b/operator/main.go index aa111952..8d31b90e 100644 --- a/operator/main.go +++ b/operator/main.go @@ -33,6 +33,7 @@ import ( httpv1alpha1 "github.com/kedacore/http-add-on/operator/api/v1alpha1" "github.com/kedacore/http-add-on/operator/controllers" "github.com/kedacore/http-add-on/operator/controllers/config" + kedahttp "github.com/kedacore/http-add-on/pkg/http" "github.com/kedacore/http-add-on/pkg/routing" // +kubebuilder:scaffold:imports ) @@ -132,7 +133,7 @@ func main() { "port", adminPort, ) - return http.ListenAndServe(addr, mux) + return kedahttp.ServeContext(ctx, addr, mux) }) setupLog.Error(errGrp.Wait(), "running the operator") diff --git a/scaler/main.go b/scaler/main.go index 3e3cf8c0..9765c97c 100644 --- a/scaler/main.go +++ b/scaler/main.go @@ -15,6 +15,7 @@ import ( "time" "github.com/go-logr/logr" + kedahttp "github.com/kedacore/http-add-on/pkg/http" "github.com/kedacore/http-add-on/pkg/k8s" pkglog "github.com/kedacore/http-add-on/pkg/log" "github.com/kedacore/http-add-on/pkg/queue" @@ -131,7 +132,6 @@ func startGrpcServer( lis.Close() }() return grpcServer.Serve(lis) - } func startHealthcheckServer( @@ -176,15 +176,7 @@ func startHealthcheckServer( } }) - srv := &http.Server{ - Addr: fmt.Sprintf(":%d", port), - Handler: mux, - } + addr := fmt.Sprintf(":%d", port) lggr.Info("starting health check server", "port", port) - - go func() { - <-ctx.Done() - srv.Shutdown(ctx) - }() - return srv.ListenAndServe() + return kedahttp.ServeContext(ctx, addr, mux) }