From 3799ffa0a894507e7982a51cf3cc2d74c4816191 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 20 Sep 2016 16:52:36 +0200 Subject: [PATCH] Simplify genericapiserver.Run() --- pkg/genericapiserver/genericapiserver.go | 25 +++++++++--------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/pkg/genericapiserver/genericapiserver.go b/pkg/genericapiserver/genericapiserver.go index d0ebc11ac28..4b61f5cc2ae 100644 --- a/pkg/genericapiserver/genericapiserver.go +++ b/pkg/genericapiserver/genericapiserver.go @@ -248,12 +248,9 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) { s.InstallOpenAPI() } - secureLocation := "" - if options.SecurePort != 0 { - secureLocation = net.JoinHostPort(options.BindAddress.String(), strconv.Itoa(options.SecurePort)) - } secureStartedCh := make(chan struct{}) - if secureLocation != "" { + if options.SecurePort != 0 { + secureLocation := net.JoinHostPort(options.BindAddress.String(), strconv.Itoa(options.SecurePort)) secureServer := &http.Server{ Addr: secureLocation, Handler: s.Handler, @@ -301,10 +298,6 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) { notifyStarted := sync.Once{} for { - // err == systemd.SdNotifyNoSocket when not running on a systemd system - if err := systemd.SdNotify("READY=1\n"); err != nil && err != systemd.SdNotifyNoSocket { - glog.Errorf("Unable to send systemd daemon successful start message: %v\n", err) - } if err := secureServer.ListenAndServeTLS(options.TLSCertFile, options.TLSPrivateKeyFile); err != nil { glog.Errorf("Unable to listen for secure (%v); will try again.", err) } else { @@ -316,20 +309,15 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) { } }() } else { - // err == systemd.SdNotifyNoSocket when not running on a systemd system - if err := systemd.SdNotify("READY=1\n"); err != nil && err != systemd.SdNotifyNoSocket { - glog.Errorf("Unable to send systemd daemon successful start message: %v\n", err) - } close(secureStartedCh) } insecureLocation := net.JoinHostPort(options.InsecureBindAddress.String(), strconv.Itoa(options.InsecurePort)) - http := &http.Server{ + insecureServer := &http.Server{ Addr: insecureLocation, Handler: s.InsecureHandler, MaxHeaderBytes: 1 << 20, } - insecureStartedCh := make(chan struct{}) glog.Infof("Serving insecurely on %s", insecureLocation) go func() { @@ -337,7 +325,7 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) { notifyStarted := sync.Once{} for { - if err := http.ListenAndServe(); err != nil { + if err := insecureServer.ListenAndServe(); err != nil { glog.Errorf("Unable to listen for insecure (%v); will try again.", err) } else { notifyStarted.Do(func() { @@ -352,6 +340,11 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) { <-insecureStartedCh s.RunPostStartHooks(PostStartHookContext{}) + // err == systemd.SdNotifyNoSocket when not running on a systemd system + if err := systemd.SdNotify("READY=1\n"); err != nil && err != systemd.SdNotifyNoSocket { + glog.Errorf("Unable to send systemd daemon successful start message: %v\n", err) + } + select {} }