Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cmd/mcp-operator/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions cmd/mcp-operator/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package app
import (
goflag "flag"
"fmt"
"os"
"regexp"
"strings"
"time"

Expand All @@ -27,6 +29,9 @@ import (

const (
ControllerIDManagedControlPlane = "managedcontrolplane"
PprofEnabledEnvVar = "ENABLE_PROFILER"
PprofAddrEnvVar = "PROFILER_ADDRESS"
PprofDefaultAddr = ":8082"
)

var (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down