Merge pull request #35292 from sttts/sttts-bindnetwork

Automatic merge from submit-queue

Add BindNetwork to genericapiserver Config

This is needed for downstream use:

`BindNetwork` is the type of network to bind to - defaults to "tcp4", accepts "tcp", "tcp4", and "tcp6".
This commit is contained in:
Kubernetes Submit Queue 2016-11-03 06:23:14 -07:00 committed by GitHub
commit 356b28b761
2 changed files with 11 additions and 4 deletions

View File

@ -177,6 +177,9 @@ type Config struct {
type ServingInfo struct {
// BindAddress is the ip:port to serve on
BindAddress string
// BindNetwork is the type of network to bind to - defaults to "tcp", accepts "tcp",
// "tcp4", and "tcp6".
BindNetwork string
}
type SecureServingInfo struct {

View File

@ -89,7 +89,7 @@ func (s *GenericAPIServer) serveSecurely(stopCh <-chan struct{}) error {
}
glog.Infof("Serving securely on %s", s.SecureServingInfo.BindAddress)
s.effectiveSecurePort, err = runServer(secureServer, stopCh)
s.effectiveSecurePort, err = runServer(secureServer, s.SecureServingInfo.BindNetwork, stopCh)
return err
}
@ -104,19 +104,23 @@ func (s *GenericAPIServer) serveInsecurely(stopCh <-chan struct{}) error {
}
glog.Infof("Serving insecurely on %s", s.InsecureServingInfo.BindAddress)
var err error
s.effectiveInsecurePort, err = runServer(insecureServer, stopCh)
s.effectiveInsecurePort, err = runServer(insecureServer, s.InsecureServingInfo.BindNetwork, stopCh)
return err
}
// runServer listens on the given port, then spawns a go-routine continuously serving
// until the stopCh is closed. The port is returned. This function does not block.
func runServer(server *http.Server, stopCh <-chan struct{}) (int, error) {
func runServer(server *http.Server, network string, stopCh <-chan struct{}) (int, error) {
if len(server.Addr) == 0 {
return 0, errors.New("address cannot be empty")
}
if len(network) == 0 {
network = "tcp"
}
// first listen is synchronous (fail early!)
ln, err := net.Listen("tcp", server.Addr)
ln, err := net.Listen(network, server.Addr)
if err != nil {
return 0, fmt.Errorf("failed to listen on %v: %v", server.Addr, err)
}