@@ -132,7 +132,16 @@ type asyncResult struct {
132132 error error
133133}
134134
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+
136145 auth := authHandler {downstream : promhttp .Handler (), ctx : ctx , client : client .TokenReviews ()}
137146 handler := http .NewServeMux ()
138147 handler .Handle ("/metrics" , & auth )
@@ -246,7 +255,7 @@ func handleServerResult(result asyncResult, lastLoopError error) error {
246255// Also detects changes to metrics certificate files upon which
247256// the metrics HTTP server is shutdown and recreated with a new
248257// 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 {
250259 var tlsConfig * tls.Config
251260 if listenAddress != "" {
252261 var err error
@@ -263,7 +272,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
263272 return fmt .Errorf ("failed to create config: %w" , err )
264273 }
265274
266- server := createHttpServer (runContext , client )
275+ server := createHttpServer (runContext , client , disableMetricsAuth )
267276
268277 resultChannel := make (chan asyncResult , 1 )
269278 resultChannelCount := 1
@@ -317,7 +326,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
317326 case result := <- resultChannel : // crashed before a shutdown was requested or metrics server recreated
318327 if restartServer {
319328 klog .Info ("Creating metrics server with updated TLS configuration." )
320- server = createHttpServer (runContext , client )
329+ server = createHttpServer (runContext , client , disableMetricsAuth )
321330 go startListening (server , tlsConfig , listenAddress , resultChannel )
322331 restartServer = false
323332 continue
0 commit comments