@@ -20,8 +20,6 @@ import (
2020 "context"
2121 "flag"
2222 "fmt"
23- "net/http"
24- "net/http/pprof"
2523 "os"
2624 "time"
2725
@@ -39,11 +37,9 @@ import (
3937 "github.com/spf13/pflag"
4038 corev1 "k8s.io/api/core/v1"
4139 "k8s.io/apimachinery/pkg/runtime"
42- "k8s.io/apiserver/pkg/server/routes"
4340 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
4441 "k8s.io/client-go/tools/leaderelection/resourcelock"
4542 cgrecord "k8s.io/client-go/tools/record"
46- "k8s.io/component-base/logs"
4743 "k8s.io/klog/v2"
4844 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
4945 "sigs.k8s.io/cluster-api-provider-azure/controllers"
@@ -60,14 +56,13 @@ import (
6056 "sigs.k8s.io/cluster-api/controllers/remote"
6157 expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
6258 capifeature "sigs.k8s.io/cluster-api/feature"
59+ "sigs.k8s.io/cluster-api/util/flags"
6360 "sigs.k8s.io/cluster-api/util/record"
6461 ctrl "sigs.k8s.io/controller-runtime"
6562 "sigs.k8s.io/controller-runtime/pkg/cache"
6663 "sigs.k8s.io/controller-runtime/pkg/client"
6764 "sigs.k8s.io/controller-runtime/pkg/controller"
6865 "sigs.k8s.io/controller-runtime/pkg/manager"
69- "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
70- metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
7166 "sigs.k8s.io/controller-runtime/pkg/webhook"
7267)
7368
@@ -115,7 +110,7 @@ var (
115110 healthAddr string
116111 webhookPort int
117112 webhookCertDir string
118- diagnosticsOptions = DiagnosticsOptions {}
113+ diagnosticsOptions = flags. DiagnosticsOptions {}
119114 timeouts reconciler.Timeouts
120115 enableTracing bool
121116)
@@ -258,7 +253,7 @@ func InitFlags(fs *pflag.FlagSet) {
258253 "Enable tracing to the opentelemetry-collector service in the same namespace." ,
259254 )
260255
261- AddDiagnosticsOptions (fs , & diagnosticsOptions )
256+ flags . AddDiagnosticsOptions (fs , & diagnosticsOptions )
262257
263258 feature .MutableGates .AddFlag (fs )
264259}
@@ -282,7 +277,7 @@ func main() {
282277 BurstSize : 100 ,
283278 })
284279
285- diagnosticsOpts := GetDiagnosticsOptions (diagnosticsOptions )
280+ diagnosticsOpts := flags . GetDiagnosticsOptions (diagnosticsOptions )
286281
287282 var watchNamespaces map [string ]cache.Config
288283 if watchNamespace != "" {
@@ -652,68 +647,3 @@ func registerWebhooks(mgr manager.Manager) {
652647 os .Exit (1 )
653648 }
654649}
655-
656- // DiagnosticsOptions is CAPI 1.6's (util/flags).DiagnosticsOptions.
657- type DiagnosticsOptions struct {
658- // MetricsBindAddr
659- //
660- // Deprecated: This field will be removed in an upcoming release.
661- MetricsBindAddr string
662- DiagnosticsAddress string
663- InsecureDiagnostics bool
664- }
665-
666- // AddDiagnosticsOptions is CAPI 1.6's (util/flags).AddDiagnosticsOptions.
667- func AddDiagnosticsOptions (fs * pflag.FlagSet , options * DiagnosticsOptions ) {
668- fs .StringVar (& options .MetricsBindAddr , "metrics-bind-addr" , "" ,
669- "The address the metrics endpoint binds to." )
670- _ = fs .MarkDeprecated ("metrics-bind-addr" , "Please use --diagnostics-address instead. To continue to serve" +
671- "metrics via http and without authentication/authorization set --insecure-diagnostics as well." )
672-
673- fs .StringVar (& options .DiagnosticsAddress , "diagnostics-address" , ":8443" ,
674- "The address the diagnostics endpoint binds to. Per default metrics are served via https and with" +
675- "authentication/authorization. To serve via http and without authentication/authorization set --insecure-diagnostics." +
676- "If --insecure-diagnostics is not set the diagnostics endpoint also serves pprof endpoints and an endpoint to change the log level." )
677-
678- fs .BoolVar (& options .InsecureDiagnostics , "insecure-diagnostics" , false ,
679- "Enable insecure diagnostics serving. For more details see the description of --diagnostics-address." )
680- }
681-
682- // GetDiagnosticsOptions is CAPI 1.6's (util/flags).GetDiagnosticsOptions.
683- func GetDiagnosticsOptions (options DiagnosticsOptions ) metricsserver.Options {
684- // If the deprecated "--metrics-bind-addr" flag is set, continue to serve metrics via http
685- // and without authentication/authorization.
686- if options .MetricsBindAddr != "" {
687- return metricsserver.Options {
688- BindAddress : options .MetricsBindAddr ,
689- }
690- }
691-
692- // If "--insecure-diagnostics" is set, serve metrics via http
693- // and without authentication/authorization.
694- if options .InsecureDiagnostics {
695- return metricsserver.Options {
696- BindAddress : options .DiagnosticsAddress ,
697- SecureServing : false ,
698- }
699- }
700-
701- // If "--insecure-diagnostics" is not set, serve metrics via https
702- // and with authentication/authorization. As the endpoint is protected,
703- // we also serve pprof endpoints and an endpoint to change the log level.
704- return metricsserver.Options {
705- BindAddress : options .DiagnosticsAddress ,
706- SecureServing : true ,
707- FilterProvider : filters .WithAuthenticationAndAuthorization ,
708- ExtraHandlers : map [string ]http.Handler {
709- // Add handler to dynamically change log level.
710- "/debug/flags/v" : routes .StringFlagPutHandler (logs .GlogSetter ),
711- // Add pprof handler.
712- "/debug/pprof/" : http .HandlerFunc (pprof .Index ),
713- "/debug/pprof/cmdline" : http .HandlerFunc (pprof .Cmdline ),
714- "/debug/pprof/profile" : http .HandlerFunc (pprof .Profile ),
715- "/debug/pprof/symbol" : http .HandlerFunc (pprof .Symbol ),
716- "/debug/pprof/trace" : http .HandlerFunc (pprof .Trace ),
717- },
718- }
719- }
0 commit comments