Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/cvo/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ type asyncResult struct {
error error
}

func createHttpServer(ctx context.Context, client *authenticationclientsetv1.AuthenticationV1Client) *http.Server {
func createHttpServer(ctx context.Context, client *authenticationclientsetv1.AuthenticationV1Client, disableAuth bool) *http.Server {
if disableAuth {
handler := http.NewServeMux()
handler.Handle("/metrics", promhttp.Handler())
server := &http.Server{
Handler: handler,
}
return server
}
Comment on lines +136 to +143
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the code prior to #1223


auth := authHandler{downstream: promhttp.Handler(), ctx: ctx, client: client.TokenReviews()}
handler := http.NewServeMux()
handler.Handle("/metrics", &auth)
Expand Down Expand Up @@ -242,7 +251,7 @@ func handleServerResult(result asyncResult, lastLoopError error) error {
// Also detects changes to metrics certificate files upon which
// the metrics HTTP server is shutdown and recreated with a new
// TLS configuration.
func RunMetrics(runContext context.Context, shutdownContext context.Context, listenAddress, certFile, keyFile string, restConfig *rest.Config) error {
func RunMetrics(runContext context.Context, shutdownContext context.Context, listenAddress, certFile, keyFile string, restConfig *rest.Config, disableMetricsAuth bool) error {
var tlsConfig *tls.Config
if listenAddress != "" {
var err error
Expand All @@ -259,7 +268,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
return fmt.Errorf("failed to create config: %w", err)
}

server := createHttpServer(runContext, client)
server := createHttpServer(runContext, client, disableMetricsAuth)

resultChannel := make(chan asyncResult, 1)
resultChannelCount := 1
Expand Down Expand Up @@ -313,7 +322,7 @@ func RunMetrics(runContext context.Context, shutdownContext context.Context, lis
case result := <-resultChannel: // crashed before a shutdown was requested or metrics server recreated
if restartServer {
klog.Info("Creating metrics server with updated TLS configuration.")
server = createHttpServer(runContext, client)
server = createHttpServer(runContext, client, disableMetricsAuth)
go startListening(server, tlsConfig, listenAddress, resultChannel)
restartServer = false
continue
Expand Down
3 changes: 2 additions & 1 deletion pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock resource
resultChannelCount++
go func() {
defer utilruntime.HandleCrash()
err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, o.ServingCertFile, o.ServingKeyFile, restConfig)
disableMetricsAuth := o.InjectClusterIdIntoPromQL // this is wired to the "--hypershift" flag, so when hypershfit is no, we disableMetricsAuth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have direct access to o.HyperShift here, so you can just use that instead of creating a local disableMetricsAuth variable, without having to touch o.InjectClusterIdIntoPromQL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, o.ServingCertFile, o.ServingKeyFile, restConfig, disableMetricsAuth)
resultChannel <- asyncResult{name: "metrics server", error: err}
}()
}
Expand Down