Skip to content

Commit e47ae18

Browse files
committed
pkg/cvo/metrics: Add more fields to MetricsOptions
1 parent 3cd9e22 commit e47ae18

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

pkg/cvo/metrics.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ func handleServerResult(result asyncResult, lastLoopError error) error {
202202
}
203203

204204
type 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

pkg/start/start.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,13 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock resource
351351
go func() {
352352
defer utilruntime.HandleCrash()
353353
options := cvo.MetricsOptions{
354+
ListenAddress: o.ListenAddr,
355+
ServingCertFile: o.ServingCertFile,
356+
ServingKeyFile: o.ServingKeyFile,
354357
DisableAuthentication: o.HyperShift,
355358
DisableAuthorization: o.HyperShift,
356359
}
357-
err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, o.ServingCertFile, o.ServingKeyFile, restConfig, options)
360+
err := cvo.RunMetrics(postMainContext, shutdownContext, restConfig, options)
358361
resultChannel <- asyncResult{name: "metrics server", error: err}
359362
}()
360363
}

0 commit comments

Comments
 (0)