Skip to content

Commit 50084e4

Browse files
Router should expose metrics via service serving cert
When router stats are on, use the service serving cert always
1 parent cf406ea commit 50084e4

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

pkg/oc/admin/router/router.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,27 @@ func generateSecretsConfig(cfg *RouterConfig, namespace string, defaultCert []by
388388
secrets = append(secrets, secret)
389389
}
390390

391+
if cfg.Type == "haproxy-router" && cfg.StatsPort != 0 {
392+
metricsCertName := "router-metrics-tls"
393+
if len(defaultCert) == 0 {
394+
// when we are generating a serving cert, we need to reuse the existing cert
395+
metricsCertName = certName
396+
}
397+
volumes = append(volumes, kapi.Volume{
398+
Name: "metrics-server-certificate",
399+
VolumeSource: kapi.VolumeSource{
400+
Secret: &kapi.SecretVolumeSource{
401+
SecretName: metricsCertName,
402+
},
403+
},
404+
})
405+
mounts = append(mounts, kapi.VolumeMount{
406+
Name: "metrics-server-certificate",
407+
ReadOnly: true,
408+
MountPath: "/etc/pki/tls/metrics/",
409+
})
410+
}
411+
391412
// The secret in this volume is either the one created for the
392413
// user supplied default cert (pem format) or the secret generated
393414
// by the service anotation (cert only format).
@@ -685,6 +706,8 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
685706
if cfg.Type == "haproxy-router" && cfg.StatsPort != 0 {
686707
env["ROUTER_LISTEN_ADDR"] = fmt.Sprintf("0.0.0.0:%d", cfg.StatsPort)
687708
env["ROUTER_METRICS_TYPE"] = "haproxy"
709+
env["ROUTER_METRICS_TLS_CERT_FILE"] = "/etc/pki/tls/metrics/tls.crt"
710+
env["ROUTER_METRICS_TLS_KEY_FILE"] = "/etc/pki/tls/metrics/tls.key"
688711
}
689712
env.Add(secretEnv)
690713
if len(defaultCert) > 0 {
@@ -730,13 +753,6 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
730753
},
731754
}
732755

733-
if cfg.StatsPort > 0 && cfg.ExposeMetrics {
734-
pc := generateMetricsExporterContainer(cfg, env)
735-
if pc != nil {
736-
containers = append(containers, *pc)
737-
}
738-
}
739-
740756
objects := []runtime.Object{}
741757
for _, s := range secrets {
742758
objects = append(objects, s)
@@ -815,6 +831,9 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
815831
// The secret generated by the service annotaion contains a tls.crt and tls.key
816832
// which ultimately need to be combined into a pem
817833
t.Annotations["service.alpha.openshift.io/serving-cert-secret-name"] = certName
834+
} else if cfg.Type == "haproxy-router" && cfg.StatsPort != 0 {
835+
// Generate a serving cert for metrics only
836+
t.Annotations["service.alpha.openshift.io/serving-cert-secret-name"] = "router-metrics-tls"
818837
}
819838
}
820839
}

0 commit comments

Comments
 (0)