@@ -45,6 +45,7 @@ import (
45
45
"sigs.k8s.io/controller-runtime/pkg/controller"
46
46
"sigs.k8s.io/controller-runtime/pkg/healthz"
47
47
"sigs.k8s.io/controller-runtime/pkg/manager"
48
+ "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
48
49
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
49
50
"sigs.k8s.io/controller-runtime/pkg/webhook"
50
51
@@ -62,8 +63,8 @@ import (
62
63
63
64
var (
64
65
setupLog = ctrl .Log .WithName ("setup" )
65
- metricsAddr string
66
- probeAddr string
66
+ diagnosticsAddress string
67
+ insecureDiagnostics bool
67
68
shardKey string
68
69
workers int
69
70
concurrentReconciles int
75
76
webhookPort int
76
77
syncPeriod time.Duration
77
78
version string
79
+ healthAddr string
78
80
)
79
81
80
82
const (
@@ -84,6 +86,10 @@ const (
84
86
defaulReportMode = int (controllers .CollectFromManagementCluster )
85
87
)
86
88
89
+ // Add RBAC for the authorized diagnostics endpoint.
90
+ // +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
91
+ // +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
92
+
87
93
func main () {
88
94
scheme , err := controllers .InitScheme ()
89
95
if err != nil {
@@ -103,10 +109,8 @@ func main() {
103
109
104
110
ctrlOptions := ctrl.Options {
105
111
Scheme : scheme ,
106
- HealthProbeBindAddress : probeAddr ,
107
- Metrics : metricsserver.Options {
108
- BindAddress : metricsAddr ,
109
- },
112
+ Metrics : getDiagnosticsOptions (),
113
+ HealthProbeBindAddress : healthAddr ,
110
114
WebhookServer : webhook .NewServer (
111
115
webhook.Options {
112
116
Port : webhookPort ,
@@ -193,15 +197,13 @@ func initFlags(fs *pflag.FlagSet) {
193
197
false ,
194
198
"When set, indicates drift-detection-manager needs to be started in the management cluster" )
195
199
196
- fs .StringVar (& metricsAddr ,
197
- "metrics-bind- address" ,
198
- ":8080" ,
199
- "The address the metric endpoint binds to ." )
200
+ fs .StringVar (& diagnosticsAddress , "diagnostics-address" , ":8443" ,
201
+ "The address the diagnostics endpoint binds to. Per default metrics are served via https and with" +
202
+ "authentication/authorization. To serve via http and without authentication/authorization set --insecure-diagnostics." +
203
+ "If --insecure-diagnostics is not set the diagnostics endpoint also serves pprof endpoints and an endpoint to change the log level ." )
200
204
201
- fs .StringVar (& probeAddr ,
202
- "health-probe-bind-address" ,
203
- ":8081" ,
204
- "The address the probe endpoint binds to." )
205
+ fs .BoolVar (& insecureDiagnostics , "insecure-diagnostics" , false ,
206
+ "Enable insecure diagnostics serving. For more details see the description of --diagnostics-address." )
205
207
206
208
fs .StringVar (& shardKey ,
207
209
"shard-key" ,
@@ -225,6 +227,9 @@ func initFlags(fs *pflag.FlagSet) {
225
227
"" ,
226
228
"current sveltos version" )
227
229
230
+ fs .StringVar (& healthAddr , "health-addr" , ":9440" ,
231
+ "The address the health endpoint binds to." )
232
+
228
233
const defautlRestConfigQPS = 20
229
234
fs .Float32Var (& restConfigQPS , "kube-api-qps" , defautlRestConfigQPS ,
230
235
fmt .Sprintf ("Maximum queries per second from the controller client to the Kubernetes API server. Defaults to %d" ,
@@ -453,3 +458,24 @@ func getClusterSummaryReconciler(ctx context.Context, mgr manager.Manager) *cont
453
458
ConcurrentReconciles : concurrentReconciles ,
454
459
}
455
460
}
461
+
462
+ // getDiagnosticsOptions returns metrics options which can be used to configure a Manager.
463
+ func getDiagnosticsOptions () metricsserver.Options {
464
+ // If "--insecure-diagnostics" is set, serve metrics via http
465
+ // and without authentication/authorization.
466
+ if insecureDiagnostics {
467
+ return metricsserver.Options {
468
+ BindAddress : diagnosticsAddress ,
469
+ SecureServing : false ,
470
+ }
471
+ }
472
+
473
+ // If "--insecure-diagnostics" is not set, serve metrics via https
474
+ // and with authentication/authorization. As the endpoint is protected,
475
+ // we also serve pprof endpoints and an endpoint to change the log level.
476
+ return metricsserver.Options {
477
+ BindAddress : diagnosticsAddress ,
478
+ SecureServing : true ,
479
+ FilterProvider : filters .WithAuthenticationAndAuthorization ,
480
+ }
481
+ }
0 commit comments