Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Flow Metrics with Openshift Auth #1603

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 8 additions & 2 deletions client/router_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ func (cli *VanClient) GetVanControllerSpec(options types.SiteConfigSpec, van *ty
mounts = append(mounts, []corev1.VolumeMount{})
if options.AuthMode == string(types.ConsoleAuthModeOpenshift) {
csp := strconv.Itoa(int(types.ConsoleOpenShiftServicePort))
metricsPort := strconv.Itoa(int(types.FlowCollectorDefaultServicePort))
envVars = append(envVars, corev1.EnvVar{Name: "FLOW_METRICS_PORT", Value: metricsPort})
envVars = append(envVars, corev1.EnvVar{Name: "FLOW_PORT", Value: csp})
envVars = append(envVars, corev1.EnvVar{Name: "FLOW_HOST", Value: "localhost"})
mounts = append(mounts, []corev1.VolumeMount{})
Expand Down Expand Up @@ -459,6 +461,12 @@ func (cli *VanClient) GetVanControllerSpec(options types.SiteConfigSpec, van *ty
if options.IsConsoleIngressRoute() {
annotations = getServingSecretAnnotations(types.ConsoleServerSecret)
if options.AuthMode == string(types.ConsoleAuthModeOpenshift) {
controllerPorts = append(controllerPorts, corev1.ServicePort{
Name: "cluster-metrics",
Protocol: "TCP",
Port: types.FlowCollectorDefaultServicePort,
TargetPort: intstr.FromInt(int(types.FlowCollectorDefaultServiceTargetPort)),
})
metricsPort = corev1.ServicePort{
Name: "metrics",
Protocol: "TCP",
Expand Down Expand Up @@ -1757,8 +1765,6 @@ func (cli *VanClient) createPrometheus(ctx context.Context, siteConfig *types.Si
ServiceName: types.ControllerServiceName,
Namespace: van.Namespace,
Port: strconv.Itoa(int(types.FlowCollectorDefaultServicePort)),
User: "admin",
Password: "admin",
Hash: "",
}
if siteConfig.Spec.PrometheusServer.AuthMode == string(types.PrometheusAuthModeBasic) {
Expand Down
35 changes: 35 additions & 0 deletions cmd/flow-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"crypto/tls"
"encoding/base64"
"encoding/json"
"errors"
Expand Down Expand Up @@ -597,6 +598,40 @@ func main() {
}
}
}()
if metricsPort := os.Getenv("FLOW_METRICS_PORT"); metricsPort != "" {
pn, err := strconv.Atoi(metricsPort)
if err != nil {
log.Fatalf("invalid FLOW_METRICS_PORT %q should be number", metricsPort)
}
if pn < 0 || (1<<16-1) < pn {
log.Fatalf("invalid FLOW_METRICS_PORT %q soutside range", metricsPort)
}

tlsCfg := tlscfg.Modern()
secret := certs.GenerateCASecret("collector-ca", "collector-api")
cert, err := tls.X509KeyPair(secret.Data["tls.crt"], secret.Data["tls.key"])
if err != nil {
log.Fatalf("error generating tls certificates for metrics server: %s", err)
}
tlsCfg.Certificates = []tls.Certificate{cert}

maddr := fmt.Sprintf(":%d", pn)
log.Printf("COLLECTOR: metrics server listening on %s", maddr)
metricsSrv := &http.Server{
Addr: maddr,
Handler: handlers.LoggingHandler(os.Stdout, promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg})),
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
TLSConfig: tlsCfg,
}
go func() {
err := metricsSrv.ListenAndServeTLS("", "")
if err != nil {
log.Printf("metrics server error: %s", err)
}
}()
}

if *isProf {
// serve only over localhost loopback
go func() {
Expand Down