pass listener in integration test to prevent port in use flake

Kubernetes-commit: a6c43c6a5ca7cc4449684d5e68d73773be91cd41
This commit is contained in:
hzxuzhonghu 2018-01-29 11:58:23 +08:00 committed by Kubernetes Publisher
parent 4d11630801
commit 808a483472
1 changed files with 9 additions and 2 deletions

View File

@ -35,7 +35,8 @@ import (
type SecureServingOptions struct {
BindAddress net.IP
BindPort int
// BindPort is ignored when Listener is set, will serve https even with 0.
BindPort int
// BindNetwork is the type of network to bind to - defaults to "tcp", accepts "tcp",
// "tcp4", and "tcp6".
BindNetwork string
@ -160,7 +161,7 @@ func (s *SecureServingOptions) ApplyTo(c *server.Config) error {
if s == nil {
return nil
}
if s.BindPort <= 0 {
if s.BindPort <= 0 && s.Listener == nil {
return nil
}
@ -171,6 +172,12 @@ func (s *SecureServingOptions) ApplyTo(c *server.Config) error {
if err != nil {
return fmt.Errorf("failed to create listener: %v", err)
}
} else {
if _, ok := s.Listener.Addr().(*net.TCPAddr); !ok {
return fmt.Errorf("failed to parse ip and port from listener")
}
s.BindPort = s.Listener.Addr().(*net.TCPAddr).Port
s.BindAddress = s.Listener.Addr().(*net.TCPAddr).IP
}
if err := s.applyServingInfoTo(c); err != nil {