@@ -3,6 +3,8 @@ package app
33import (
44 goflag "flag"
55 "fmt"
6+ "os"
7+ "regexp"
68 "strings"
79 "time"
810
@@ -27,6 +29,9 @@ import (
2729
2830const (
2931 ControllerIDManagedControlPlane = "managedcontrolplane"
32+ PprofEnabledEnvVar = "ENABLE_PROFILER"
33+ PprofAddrEnvVar = "PROFILER_ADDRESS"
34+ PprofDefaultAddr = ":8082"
3035)
3136
3237var (
@@ -101,6 +106,9 @@ type Options struct {
101106 ActiveControllers sets.Set [string ]
102107 WebhooksFlags * webhooks.Flags
103108 CRDFlags * crds.Flags
109+
110+ // options based on env vars
111+ PprofAddr string `json:"pprofAddr"`
104112}
105113
106114func NewOptions () * Options {
@@ -146,6 +154,12 @@ func (o *Options) String(includeHeader bool, includeRawOptions bool) (string, er
146154 opts ["authConfig" ] = o .AuthConfig
147155 opts ["authzConfig" ] = o .AuthzConfig
148156
157+ if o .PprofAddr == "" {
158+ opts ["pprof" ] = "disabled"
159+ } else {
160+ opts ["pprof" ] = o .PprofAddr
161+ }
162+
149163 // controllers
150164 opts ["activeControllers" ] = sets .List (o .ActiveControllers )
151165
@@ -312,6 +326,17 @@ func (o *Options) Complete() error {
312326 }
313327 }
314328
329+ // evaluate env vars
330+ if os .Getenv (PprofEnabledEnvVar ) == "true" {
331+ o .PprofAddr = os .Getenv (PprofAddrEnvVar )
332+ if o .PprofAddr == "" {
333+ o .PprofAddr = PprofDefaultAddr
334+ } else if regexp .MustCompile (`^[0-9]{1,5}$` ).MatchString (o .PprofAddr ) {
335+ // if only a port is given, prepend a colon
336+ o .PprofAddr = ":" + o .PprofAddr
337+ }
338+ }
339+
315340 // print options
316341 optsString , err := o .String (true , false )
317342 if err != nil {
0 commit comments