@@ -20,8 +20,6 @@ import (
2020 "context"
2121 "flag"
2222 "fmt"
23- "net/http"
24- "net/http/pprof"
2523 "os"
2624 "time"
2725
@@ -36,11 +34,9 @@ import (
3634 "github.com/spf13/pflag"
3735 corev1 "k8s.io/api/core/v1"
3836 "k8s.io/apimachinery/pkg/runtime"
39- "k8s.io/apiserver/pkg/server/routes"
4037 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
4138 "k8s.io/client-go/tools/leaderelection/resourcelock"
4239 cgrecord "k8s.io/client-go/tools/record"
43- "k8s.io/component-base/logs"
4440 "k8s.io/klog/v2"
4541 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
4642 "sigs.k8s.io/cluster-api-provider-azure/controllers"
@@ -57,14 +53,13 @@ import (
5753 "sigs.k8s.io/cluster-api/controllers/remote"
5854 expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
5955 capifeature "sigs.k8s.io/cluster-api/feature"
56+ "sigs.k8s.io/cluster-api/util/flags"
6057 "sigs.k8s.io/cluster-api/util/record"
6158 ctrl "sigs.k8s.io/controller-runtime"
6259 "sigs.k8s.io/controller-runtime/pkg/cache"
6360 "sigs.k8s.io/controller-runtime/pkg/client"
6461 "sigs.k8s.io/controller-runtime/pkg/controller"
6562 "sigs.k8s.io/controller-runtime/pkg/manager"
66- "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
67- metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
6863 "sigs.k8s.io/controller-runtime/pkg/webhook"
6964)
7065
@@ -109,7 +104,7 @@ var (
109104 healthAddr string
110105 webhookPort int
111106 webhookCertDir string
112- diagnosticsOptions = DiagnosticsOptions {}
107+ diagnosticsOptions = flags. DiagnosticsOptions {}
113108 timeouts reconciler.Timeouts
114109 enableTracing bool
115110)
@@ -252,7 +247,7 @@ func InitFlags(fs *pflag.FlagSet) {
252247 "Enable tracing to the opentelemetry-collector service in the same namespace." ,
253248 )
254249
255- AddDiagnosticsOptions (fs , & diagnosticsOptions )
250+ flags . AddDiagnosticsOptions (fs , & diagnosticsOptions )
256251
257252 feature .MutableGates .AddFlag (fs )
258253}
@@ -276,7 +271,7 @@ func main() {
276271 BurstSize : 100 ,
277272 })
278273
279- diagnosticsOpts := GetDiagnosticsOptions (diagnosticsOptions )
274+ diagnosticsOpts := flags . GetDiagnosticsOptions (diagnosticsOptions )
280275
281276 var watchNamespaces map [string ]cache.Config
282277 if watchNamespace != "" {
@@ -646,68 +641,3 @@ func registerWebhooks(mgr manager.Manager) {
646641 os .Exit (1 )
647642 }
648643}
649-
650- // DiagnosticsOptions is CAPI 1.6's (util/flags).DiagnosticsOptions.
651- type DiagnosticsOptions struct {
652- // MetricsBindAddr
653- //
654- // Deprecated: This field will be removed in an upcoming release.
655- MetricsBindAddr string
656- DiagnosticsAddress string
657- InsecureDiagnostics bool
658- }
659-
660- // AddDiagnosticsOptions is CAPI 1.6's (util/flags).AddDiagnosticsOptions.
661- func AddDiagnosticsOptions (fs * pflag.FlagSet , options * DiagnosticsOptions ) {
662- fs .StringVar (& options .MetricsBindAddr , "metrics-bind-addr" , "" ,
663- "The address the metrics endpoint binds to." )
664- _ = fs .MarkDeprecated ("metrics-bind-addr" , "Please use --diagnostics-address instead. To continue to serve" +
665- "metrics via http and without authentication/authorization set --insecure-diagnostics as well." )
666-
667- fs .StringVar (& options .DiagnosticsAddress , "diagnostics-address" , ":8443" ,
668- "The address the diagnostics endpoint binds to. Per default metrics are served via https and with" +
669- "authentication/authorization. To serve via http and without authentication/authorization set --insecure-diagnostics." +
670- "If --insecure-diagnostics is not set the diagnostics endpoint also serves pprof endpoints and an endpoint to change the log level." )
671-
672- fs .BoolVar (& options .InsecureDiagnostics , "insecure-diagnostics" , false ,
673- "Enable insecure diagnostics serving. For more details see the description of --diagnostics-address." )
674- }
675-
676- // GetDiagnosticsOptions is CAPI 1.6's (util/flags).GetDiagnosticsOptions.
677- func GetDiagnosticsOptions (options DiagnosticsOptions ) metricsserver.Options {
678- // If the deprecated "--metrics-bind-addr" flag is set, continue to serve metrics via http
679- // and without authentication/authorization.
680- if options .MetricsBindAddr != "" {
681- return metricsserver.Options {
682- BindAddress : options .MetricsBindAddr ,
683- }
684- }
685-
686- // If "--insecure-diagnostics" is set, serve metrics via http
687- // and without authentication/authorization.
688- if options .InsecureDiagnostics {
689- return metricsserver.Options {
690- BindAddress : options .DiagnosticsAddress ,
691- SecureServing : false ,
692- }
693- }
694-
695- // If "--insecure-diagnostics" is not set, serve metrics via https
696- // and with authentication/authorization. As the endpoint is protected,
697- // we also serve pprof endpoints and an endpoint to change the log level.
698- return metricsserver.Options {
699- BindAddress : options .DiagnosticsAddress ,
700- SecureServing : true ,
701- FilterProvider : filters .WithAuthenticationAndAuthorization ,
702- ExtraHandlers : map [string ]http.Handler {
703- // Add handler to dynamically change log level.
704- "/debug/flags/v" : routes .StringFlagPutHandler (logs .GlogSetter ),
705- // Add pprof handler.
706- "/debug/pprof/" : http .HandlerFunc (pprof .Index ),
707- "/debug/pprof/cmdline" : http .HandlerFunc (pprof .Cmdline ),
708- "/debug/pprof/profile" : http .HandlerFunc (pprof .Profile ),
709- "/debug/pprof/symbol" : http .HandlerFunc (pprof .Symbol ),
710- "/debug/pprof/trace" : http .HandlerFunc (pprof .Trace ),
711- },
712- }
713- }
0 commit comments