Skip to content

refactor: Use controller manager options for pprof handler #151

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

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
31 changes: 5 additions & 26 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ package main
import (
"flag"
"fmt"
"net/http"
"os"
"time"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -36,21 +34,14 @@ import (
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/servicelbgc"
)

var (
// Flags.
profilerAddress string
logOptions = logs.NewOptions()
)
// Flags.
var logOptions = logs.NewOptions()

// initFlags initializes the flags.
func initFlags(fs *pflag.FlagSet) {
// Initialize logs flags using Kubernetes component-base machinery.
logs.AddFlags(fs, logs.SkipLoggingConfigurationFlags())
logsv1.AddFlags(logOptions, fs)

// Add test-extension specific flags
fs.StringVar(&profilerAddress, "profiler-address", "",
"Bind address to expose the pprof profiler (e.g. localhost:6060)")
}

func main() {
Expand Down Expand Up @@ -85,6 +76,9 @@ func main() {
"The address the probe endpoint binds to.",
)

pflag.CommandLine.StringVar(&mgrOptions.PprofBindAddress, "profiler-address", "",
"Bind address to expose the pprof profiler (e.g. localhost:6060)")

calicoCNIConfig := &calico.CalicoCNIConfig{}

runtimeWebhookServerOpts := server.NewServerOptions()
Expand All @@ -108,21 +102,6 @@ func main() {
// Add the klog logger in the context.
ctrl.SetLogger(klog.Background())

// Initialize the golang profiler server, if required.
if profilerAddress != "" {
klog.Infof("Profiler listening for requests at %s", profilerAddress)
go func() {
profilerServer := &http.Server{
Addr: profilerAddress,
Handler: nil,
MaxHeaderBytes: 1 << 20,
IdleTimeout: 90 * time.Second, // matches http.DefaultTransport keep-alive timeout
ReadHeaderTimeout: 32 * time.Second,
}
klog.Info(profilerServer.ListenAndServe())
}()
}

signalCtx := ctrl.SetupSignalHandler()

mgr, err := newManager(mgrOptions)
Expand Down