Skip to content

Commit 9e38619

Browse files
author
Jeff Peeler
committed
bug(metrics): serve metrics using new certs when replaced
1 parent 0d6a4d4 commit 9e38619

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

cmd/catalog/main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"crypto/tls"
56
"flag"
67
"fmt"
78
"net/http"
@@ -18,6 +19,7 @@ import (
1819

1920
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
2021
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
22+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/filemonitor"
2123
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
2224
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
2325
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/profile"
@@ -138,8 +140,20 @@ func main() {
138140
metricsMux := http.NewServeMux()
139141
metricsMux.Handle("/metrics", promhttp.Handler())
140142
if useTLS {
143+
tlsGetCertFn, err := filemonitor.OLMGetCertRotationFn(logger, *tlsCertPath, *tlsKeyPath)
144+
if err != nil {
145+
logger.Errorf("Certificate monitoring for metrics (https) failed: %v", err)
146+
}
147+
141148
go func() {
142-
err := http.ListenAndServeTLS(":8081", *tlsCertPath, *tlsKeyPath, metricsMux)
149+
httpsServer := &http.Server{
150+
Addr: ":8081",
151+
Handler: metricsMux,
152+
TLSConfig: &tls.Config{
153+
GetCertificate: tlsGetCertFn,
154+
},
155+
}
156+
err := httpsServer.ListenAndServeTLS("", "")
143157
if err != nil {
144158
logger.Errorf("Metrics (https) serving failed: %v", err)
145159
}

cmd/olm/main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"crypto/tls"
56
"flag"
67
"fmt"
78
"net/http"
@@ -18,6 +19,7 @@ import (
1819

1920
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
2021
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
22+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/filemonitor"
2123
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
2224
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
2325
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/profile"
@@ -139,8 +141,20 @@ func main() {
139141
metricsMux := http.NewServeMux()
140142
metricsMux.Handle("/metrics", promhttp.Handler())
141143
if useTLS {
144+
tlsGetCertFn, err := filemonitor.OLMGetCertRotationFn(logger, *tlsCertPath, *tlsKeyPath)
145+
if err != nil {
146+
logger.Errorf("Certificate monitoring for metrics (https) failed: %v", err)
147+
}
148+
142149
go func() {
143-
err := http.ListenAndServeTLS(":8081", *tlsCertPath, *tlsKeyPath, metricsMux)
150+
httpsServer := &http.Server{
151+
Addr: ":8081",
152+
Handler: metricsMux,
153+
TLSConfig: &tls.Config{
154+
GetCertificate: tlsGetCertFn,
155+
},
156+
}
157+
err := httpsServer.ListenAndServeTLS("", "")
144158
if err != nil {
145159
logger.Errorf("Metrics (https) serving failed: %v", err)
146160
}

0 commit comments

Comments
 (0)