@@ -101,6 +101,9 @@ type Options struct {
101101// TLSOpts is used to allow configuring the TLS config used for the server.
102102// This also allows providing a certificate via GetCertificate.
103103TLSOpts []func (* tls.Config )
104+
105+ // ListenConfig contains options for listening to an address on the metric server.
106+ ListenConfig net.ListenConfig
104107}
105108
106109// 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 {
249252
250253func (s * defaultServer ) createListener (ctx context.Context , log logr.Logger ) (net.Listener , error ) {
251254if ! s .options .SecureServing {
252- return net . Listen ("tcp" , s .options .BindAddress )
255+ return s . options . ListenConfig . Listen (ctx , "tcp" , s .options .BindAddress )
253256}
254257
255258cfg := & tls.Config { //nolint:gosec
@@ -302,7 +305,12 @@ func (s *defaultServer) createListener(ctx context.Context, log logr.Logger) (ne
302305cfg .Certificates = []tls.Certificate {keyPair }
303306}
304307
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
306314}
307315
308316func (s * defaultServer ) GetBindAddr () string {
0 commit comments