@@ -132,7 +132,16 @@ type asyncResult struct {
132
132
error error
133
133
}
134
134
135
- func createHttpServer (ctx context.Context , client * authenticationclientsetv1.AuthenticationV1Client ) * http.Server {
135
+ func createHttpServer (ctx context.Context , client * authenticationclientsetv1.AuthenticationV1Client , disableAuth bool ) * http.Server {
136
+ if disableAuth {
137
+ handler := http .NewServeMux ()
138
+ handler .Handle ("/metrics" , promhttp .Handler ())
139
+ server := & http.Server {
140
+ Handler : handler ,
141
+ }
142
+ return server
143
+ }
144
+
136
145
auth := authHandler {downstream : promhttp .Handler (), ctx : ctx , client : client .TokenReviews ()}
137
146
handler := http .NewServeMux ()
138
147
handler .Handle ("/metrics" , & auth )
@@ -246,7 +255,7 @@ func handleServerResult(result asyncResult, lastLoopError error) error {
246
255
// Also detects changes to metrics certificate files upon which
247
256
// the metrics HTTP server is shutdown and recreated with a new
248
257
// TLS configuration.
249
- func RunMetrics (runContext context.Context , shutdownContext context.Context , listenAddress , certFile , keyFile string , restConfig * rest.Config ) error {
258
+ func RunMetrics (runContext context.Context , shutdownContext context.Context , listenAddress , certFile , keyFile string , restConfig * rest.Config , disableMetricsAuth bool ) error {
250
259
var tlsConfig * tls.Config
251
260
if listenAddress != "" {
252
261
var err error
@@ -263,7 +272,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
263
272
return fmt .Errorf ("failed to create config: %w" , err )
264
273
}
265
274
266
- server := createHttpServer (runContext , client )
275
+ server := createHttpServer (runContext , client , disableMetricsAuth )
267
276
268
277
resultChannel := make (chan asyncResult , 1 )
269
278
resultChannelCount := 1
@@ -317,7 +326,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
317
326
case result := <- resultChannel : // crashed before a shutdown was requested or metrics server recreated
318
327
if restartServer {
319
328
klog .Info ("Creating metrics server with updated TLS configuration." )
320
- server = createHttpServer (runContext , client )
329
+ server = createHttpServer (runContext , client , disableMetricsAuth )
321
330
go startListening (server , tlsConfig , listenAddress , resultChannel )
322
331
restartServer = false
323
332
continue
0 commit comments