Skip to content

Commit c876a4e

Browse files
deads2kwking
authored andcommitted
temporarily disable metrics auth for hypershift clusters
CVO does not honor client certificates per the OCP metrics standard and HCP does not configure the secret. The combination of these two things means that on HCP, if we enable the CVO's auth handler, we lose the ability to determine if clusteroperators are functioning correctly at scale.
1 parent 9de00ba commit c876a4e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pkg/cvo/metrics.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

pkg/start/start.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock resource
357357
resultChannelCount++
358358
go func() {
359359
defer utilruntime.HandleCrash()
360-
err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, o.ServingCertFile, o.ServingKeyFile, restConfig)
360+
disableMetricsAuth := o.InjectClusterIdIntoPromQL // this is wired to the "--hypershift" flag, so when hypershfit is no, we disableMetricsAuth
361+
err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, o.ServingCertFile, o.ServingKeyFile, restConfig, disableMetricsAuth)
361362
resultChannel <- asyncResult{name: "metrics server", error: err}
362363
}()
363364
}

0 commit comments

Comments
 (0)