1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

fix: setup max procs with correct logger (#5059)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-10-19 12:44:29 +02:00 committed by GitHub
parent eac23af077
commit c433242cd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,7 +51,7 @@ import (
webhookspolicy "github.com/kyverno/kyverno/pkg/webhooks/policy"
webhooksresource "github.com/kyverno/kyverno/pkg/webhooks/resource"
webhookgenerate "github.com/kyverno/kyverno/pkg/webhooks/updaterequest"
_ "go.uber.org/automaxprocs" // #nosec
"go.uber.org/automaxprocs/maxprocs" // #nosec
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
coordinationv1 "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
@ -135,6 +135,17 @@ func parseFlags() error {
return nil
}
func setupMaxProcs(logger logr.Logger) (func(), error) {
logger = logger.WithName("maxprocs")
if undo, err := maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) {
logger.Info(fmt.Sprintf(format, args...))
})); err != nil {
return nil, err
} else {
return undo, nil
}
}
func startProfiling(logger logr.Logger) {
logger = logger.WithName("profiling")
logger.Info("start profiling...", "profile", profile, "port", profilePort)
@ -502,6 +513,13 @@ func main() {
os.Exit(1)
}
logger := logging.WithName("setup")
// setup maxprocs
if undo, err := setupMaxProcs(logger); err != nil {
logger.Error(err, "failed to configure maxprocs")
os.Exit(1)
} else {
defer undo()
}
// show version
showWarnings(logger)
// show version