diff --git a/cmd/mcp-operator/app/app.go b/cmd/mcp-operator/app/app.go index d10240a..7184c37 100644 --- a/cmd/mcp-operator/app/app.go +++ b/cmd/mcp-operator/app/app.go @@ -104,9 +104,6 @@ func (o *Options) runInit(ctx context.Context) error { } if o.CRDFlags.Install { - if err != nil { - return fmt.Errorf("error building setup client: %w", err) - } setupLog.Info("CRD installation configured, deploying CRDs ...") crds := crdinstall.CRDs() for _, crd := range crds { @@ -176,6 +173,7 @@ func (o *Options) run(ctx context.Context) error { RecoverPanic: ptr.To(true), }, HealthProbeBindAddress: o.ProbeAddr, + PprofBindAddress: o.PprofAddr, LeaderElection: o.EnableLeaderElection, LeaderElectionID: "mcpo.openmcp.cloud", LeaderElectionNamespace: o.LeaseNamespace, diff --git a/cmd/mcp-operator/app/options.go b/cmd/mcp-operator/app/options.go index 5683f41..e430dff 100644 --- a/cmd/mcp-operator/app/options.go +++ b/cmd/mcp-operator/app/options.go @@ -3,6 +3,8 @@ package app import ( goflag "flag" "fmt" + "os" + "regexp" "strings" "time" @@ -27,6 +29,9 @@ import ( const ( ControllerIDManagedControlPlane = "managedcontrolplane" + PprofEnabledEnvVar = "ENABLE_PROFILER" + PprofAddrEnvVar = "PROFILER_ADDRESS" + PprofDefaultAddr = ":8082" ) var ( @@ -101,6 +106,9 @@ type Options struct { ActiveControllers sets.Set[string] WebhooksFlags *webhooks.Flags CRDFlags *crds.Flags + + // options based on env vars + PprofAddr string `json:"pprofAddr"` } func NewOptions() *Options { @@ -146,6 +154,12 @@ func (o *Options) String(includeHeader bool, includeRawOptions bool) (string, er opts["authConfig"] = o.AuthConfig opts["authzConfig"] = o.AuthzConfig + if o.PprofAddr == "" { + opts["pprof"] = "disabled" + } else { + opts["pprof"] = o.PprofAddr + } + // controllers opts["activeControllers"] = sets.List(o.ActiveControllers) @@ -312,6 +326,17 @@ func (o *Options) Complete() error { } } + // evaluate env vars + if os.Getenv(PprofEnabledEnvVar) == "true" { + o.PprofAddr = os.Getenv(PprofAddrEnvVar) + if o.PprofAddr == "" { + o.PprofAddr = PprofDefaultAddr + } else if regexp.MustCompile(`^[0-9]{1,5}$`).MatchString(o.PprofAddr) { + // if only a port is given, prepend a colon + o.PprofAddr = ":" + o.PprofAddr + } + } + // print options optsString, err := o.String(true, false) if err != nil {