Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using ServeContext for all production HTTP servers #292

Merged
merged 8 commits into from
Oct 25, 2021
3 changes: 2 additions & 1 deletion operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 3 additions & 11 deletions scaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -135,7 +136,6 @@ func startGrpcServer(
lis.Close()
}()
return grpcServer.Serve(lis)

}

func startHealthcheckServer(
Expand Down Expand Up @@ -180,15 +180,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)
}