@@ -101,6 +101,9 @@ type Options struct {
101
101
// TLSOpts is used to allow configuring the TLS config used for the server.
102
102
// This also allows providing a certificate via GetCertificate.
103
103
TLSOpts []func (* tls.Config )
104
+
105
+ // ListenConfig contains options for listening to an address on the metric server.
106
+ ListenConfig net.ListenConfig
104
107
}
105
108
106
109
// Filter is a func that is added around metrics and extra handlers on the metrics server.
@@ -249,7 +252,7 @@ func (s *defaultServer) Start(ctx context.Context) error {
249
252
250
253
func (s * defaultServer ) createListener (ctx context.Context , log logr.Logger ) (net.Listener , error ) {
251
254
if ! s .options .SecureServing {
252
- return net . Listen ("tcp" , s .options .BindAddress )
255
+ return s . options . ListenConfig . Listen (ctx , "tcp" , s .options .BindAddress )
253
256
}
254
257
255
258
cfg := & tls.Config { //nolint:gosec
@@ -302,7 +305,12 @@ func (s *defaultServer) createListener(ctx context.Context, log logr.Logger) (ne
302
305
cfg .Certificates = []tls.Certificate {keyPair }
303
306
}
304
307
305
- return tls .Listen ("tcp" , s .options .BindAddress , cfg )
308
+ l , err := s .options .ListenConfig .Listen (ctx , "tcp" , s .options .BindAddress )
309
+ if err != nil {
310
+ return nil , err
311
+ }
312
+
313
+ return tls .NewListener (l , cfg ), nil
306
314
}
307
315
308
316
func (s * defaultServer ) GetBindAddr () string {
0 commit comments