Skip to content

Commit 80df72f

Browse files
authored
refactor: Use controller manager options for pprof handler (#151)
1 parent e437f57 commit 80df72f

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

cmd/main.go

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ package main
66
import (
77
"flag"
88
"fmt"
9-
"net/http"
109
"os"
11-
"time"
1210

1311
"github.com/spf13/pflag"
1412
"k8s.io/apimachinery/pkg/runtime"
@@ -36,21 +34,14 @@ import (
3634
"github.com/d2iq-labs/capi-runtime-extensions/pkg/handlers/servicelbgc"
3735
)
3836

39-
var (
40-
// Flags.
41-
profilerAddress string
42-
logOptions = logs.NewOptions()
43-
)
37+
// Flags.
38+
var logOptions = logs.NewOptions()
4439

4540
// initFlags initializes the flags.
4641
func initFlags(fs *pflag.FlagSet) {
4742
// Initialize logs flags using Kubernetes component-base machinery.
4843
logs.AddFlags(fs, logs.SkipLoggingConfigurationFlags())
4944
logsv1.AddFlags(logOptions, fs)
50-
51-
// Add test-extension specific flags
52-
fs.StringVar(&profilerAddress, "profiler-address", "",
53-
"Bind address to expose the pprof profiler (e.g. localhost:6060)")
5445
}
5546

5647
func main() {
@@ -85,6 +76,9 @@ func main() {
8576
"The address the probe endpoint binds to.",
8677
)
8778

79+
pflag.CommandLine.StringVar(&mgrOptions.PprofBindAddress, "profiler-address", "",
80+
"Bind address to expose the pprof profiler (e.g. localhost:6060)")
81+
8882
calicoCNIConfig := &calico.CalicoCNIConfig{}
8983

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

111-
// Initialize the golang profiler server, if required.
112-
if profilerAddress != "" {
113-
klog.Infof("Profiler listening for requests at %s", profilerAddress)
114-
go func() {
115-
profilerServer := &http.Server{
116-
Addr: profilerAddress,
117-
Handler: nil,
118-
MaxHeaderBytes: 1 << 20,
119-
IdleTimeout: 90 * time.Second, // matches http.DefaultTransport keep-alive timeout
120-
ReadHeaderTimeout: 32 * time.Second,
121-
}
122-
klog.Info(profilerServer.ListenAndServe())
123-
}()
124-
}
125-
126105
signalCtx := ctrl.SetupSignalHandler()
127106

128107
mgr, err := newManager(mgrOptions)

0 commit comments

Comments
 (0)