@@ -99,22 +99,35 @@ func main() {
99
99
if * tlsCertPath != "" && * tlsKeyPath == "" || * tlsCertPath == "" && * tlsKeyPath != "" {
100
100
logger .Warn ("both --tls-key and --tls-crt must be provided for TLS to be enabled, falling back to non-https" )
101
101
} else if * tlsCertPath == "" && * tlsKeyPath == "" {
102
- logger .Info ("TLS keys not set, using non-https" )
102
+ logger .Info ("TLS keys not set, using non-https for metrics " )
103
103
} else {
104
+ logger .Info ("TLS keys set, using https for metrics" )
104
105
useTLS = true
105
106
}
106
107
107
108
// Serve a health check.
108
- http .HandleFunc ("/healthz" , func (w http.ResponseWriter , r * http.Request ) {
109
+ healthMux := http .NewServeMux ()
110
+ healthMux .HandleFunc ("/healthz" , func (w http.ResponseWriter , r * http.Request ) {
109
111
w .WriteHeader (http .StatusOK )
110
112
})
111
- go http .ListenAndServe (":8080" , nil )
113
+ go http .ListenAndServe (":8080" , healthMux )
112
114
113
- http .Handle ("/metrics" , promhttp .Handler ())
115
+ metricsMux := http .NewServeMux ()
116
+ metricsMux .Handle ("/metrics" , promhttp .Handler ())
114
117
if useTLS {
115
- go http .ListenAndServeTLS (":8081" , * tlsCertPath , * tlsKeyPath , nil )
118
+ go func () {
119
+ err := http .ListenAndServeTLS (":8081" , * tlsCertPath , * tlsKeyPath , metricsMux )
120
+ if err != nil {
121
+ logger .Errorf ("Metrics (https) serving failed: %v" , err )
122
+ }
123
+ }()
116
124
} else {
117
- go http .ListenAndServe (":8081" , nil )
125
+ go func () {
126
+ err := http .ListenAndServe (":8081" , metricsMux )
127
+ if err != nil {
128
+ logger .Errorf ("Metrics (http) serving failed: %v" , err )
129
+ }
130
+ }()
118
131
}
119
132
120
133
// create a config client for operator status
0 commit comments