mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
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:
commit
356b28b761
@ -177,6 +177,9 @@ type Config struct {
|
|||||||
type ServingInfo struct {
|
type ServingInfo struct {
|
||||||
// BindAddress is the ip:port to serve on
|
// BindAddress is the ip:port to serve on
|
||||||
BindAddress string
|
BindAddress string
|
||||||
|
// BindNetwork is the type of network to bind to - defaults to "tcp", accepts "tcp",
|
||||||
|
// "tcp4", and "tcp6".
|
||||||
|
BindNetwork string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SecureServingInfo struct {
|
type SecureServingInfo struct {
|
||||||
|
@ -89,7 +89,7 @@ func (s *GenericAPIServer) serveSecurely(stopCh <-chan struct{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("Serving securely on %s", s.SecureServingInfo.BindAddress)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,19 +104,23 @@ func (s *GenericAPIServer) serveInsecurely(stopCh <-chan struct{}) error {
|
|||||||
}
|
}
|
||||||
glog.Infof("Serving insecurely on %s", s.InsecureServingInfo.BindAddress)
|
glog.Infof("Serving insecurely on %s", s.InsecureServingInfo.BindAddress)
|
||||||
var err error
|
var err error
|
||||||
s.effectiveInsecurePort, err = runServer(insecureServer, stopCh)
|
s.effectiveInsecurePort, err = runServer(insecureServer, s.InsecureServingInfo.BindNetwork, stopCh)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// runServer listens on the given port, then spawns a go-routine continuously serving
|
// 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.
|
// 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 {
|
if len(server.Addr) == 0 {
|
||||||
return 0, errors.New("address cannot be empty")
|
return 0, errors.New("address cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(network) == 0 {
|
||||||
|
network = "tcp"
|
||||||
|
}
|
||||||
|
|
||||||
// first listen is synchronous (fail early!)
|
// first listen is synchronous (fail early!)
|
||||||
ln, err := net.Listen("tcp", server.Addr)
|
ln, err := net.Listen(network, server.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("failed to listen on %v: %v", server.Addr, err)
|
return 0, fmt.Errorf("failed to listen on %v: %v", server.Addr, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user