@@ -202,6 +202,11 @@ func handleServerResult(result asyncResult, lastLoopError error) error {
202202}
203203
204204type MetricsOptions struct {
205+ ListenAddress string
206+
207+ ServingCertFile string
208+ ServingKeyFile string
209+
205210 DisableAuthentication bool
206211 DisableAuthorization bool
207212}
@@ -213,12 +218,12 @@ type MetricsOptions struct {
213218// Continues serving until runContext.Done() and then attempts a clean
214219// shutdown limited by shutdownContext.Done(). Assumes runContext.Done()
215220// occurs before or simultaneously with shutdownContext.Done().
216- func RunMetrics (runContext context.Context , shutdownContext context.Context , listenAddress , certFile , keyFile string , restConfig * rest.Config , metricsOptions MetricsOptions ) error {
217- if listenAddress == "" {
221+ func RunMetrics (runContext context.Context , shutdownContext context.Context , restConfig * rest.Config , options MetricsOptions ) error {
222+ if options . ListenAddress == "" {
218223 return errors .New ("listen address is required to serve metrics" )
219224 }
220225
221- if metricsOptions .DisableAuthentication && ! metricsOptions .DisableAuthorization {
226+ if options .DisableAuthentication && ! options .DisableAuthorization {
222227 return errors .New ("invalid configuration: cannot enable authorization without authentication" )
223228 }
224229
@@ -230,7 +235,11 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
230235 resultChannelCount := 0
231236
232237 // Create a dynamic serving cert/key controller to watch for serving certificate changes from files.
233- servingContentController , err := dynamiccertificates .NewDynamicServingContentFromFiles ("metrics-serving-cert" , certFile , keyFile )
238+ servingContentController , err := dynamiccertificates .NewDynamicServingContentFromFiles (
239+ "metrics-serving-cert" ,
240+ options .ServingCertFile ,
241+ options .ServingKeyFile ,
242+ )
234243 if err != nil {
235244 return fmt .Errorf ("failed to create serving certificate controller: %w" , err )
236245 }
@@ -248,7 +257,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
248257 clientAuth := tls .NoClientCert
249258 var clientCA dynamiccertificates.CAContentProvider
250259 var clientCAController * dynamiccertificates.ConfigMapCAController
251- if ! metricsOptions .DisableAuthentication {
260+ if ! options .DisableAuthentication {
252261 // Create a dynamic CA controller to watch for client CA changes from a ConfigMap.
253262 kubeClient , err := kubernetes .NewForConfig (restConfig )
254263 if err != nil {
@@ -318,7 +327,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
318327 resultChannel <- asyncResult {name : "serving certification controller" }
319328 }()
320329
321- server := createHttpServer (metricsOptions .DisableAuthorization )
330+ server := createHttpServer (options .DisableAuthorization )
322331 tlsConfig := crypto .SecureTLSConfig (& tls.Config {
323332 GetConfigForClient : func (clientHello * tls.ClientHelloInfo ) (* tls.Config , error ) {
324333 config , err := servingCertController .GetConfigForClient (clientHello )
@@ -336,7 +345,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
336345
337346 resultChannelCount ++
338347 go func () {
339- startListening (server , tlsConfig , listenAddress , resultChannel )
348+ startListening (server , tlsConfig , options . ListenAddress , resultChannel )
340349 }()
341350
342351 // Wait for server to exit or shutdown signal
0 commit comments