Skip to content

Commit 4b8d15e

Browse files
Merge pull request #1243 from wking/disable-metrics-auth-on-hypershift-v2
OCPBUGS-62861:temporarily disable metrics auth for hypershift clusters
2 parents 95685e0 + 8d7bf25 commit 4b8d15e

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
@@ -350,7 +350,8 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock resource
350350
resultChannelCount++
351351
go func() {
352352
defer utilruntime.HandleCrash()
353-
err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, o.ServingCertFile, o.ServingKeyFile, restConfig)
353+
disableMetricsAuth := o.InjectClusterIdIntoPromQL // this is wired to the "--hypershift" flag, so when hypershfit is no, we disableMetricsAuth
354+
err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, o.ServingCertFile, o.ServingKeyFile, restConfig, disableMetricsAuth)
354355
resultChannel <- asyncResult{name: "metrics server", error: err}
355356
}()
356357
}

0 commit comments

Comments
 (0)