Add error check in kubectl proxy on server setup

If "NewServer" returns an error, it will result in a nil pointer
dereference segfault.

A simple way to test the behavior is to prefix the server url with a
colon, ":".

Kubernetes-commit: 1e50bc2d094410f3848b4dbc5f0442440d8f7d77
This commit is contained in:
Odin Ugedal 2019-07-26 20:06:46 +02:00 committed by Kubernetes Publisher
parent 757539aac7
commit 4e367c0f16
1 changed files with 6 additions and 3 deletions

View File

@ -200,6 +200,10 @@ func (o ProxyOptions) Validate() error {
func (o ProxyOptions) RunProxy() error {
server, err := proxy.NewServer(o.staticDir, o.apiPrefix, o.staticPrefix, o.filter, o.clientConfig, o.keepalive)
if err != nil {
return err
}
// Separate listening from serving so we can report the bound port
// when it is chosen by os (eg: port == 0)
var l net.Listener
@ -209,9 +213,8 @@ func (o ProxyOptions) RunProxy() error {
l, err = server.ListenUnix(o.unixSocket)
}
if err != nil {
klog.Fatal(err)
return err
}
fmt.Fprintf(o.IOStreams.Out, "Starting to serve on %s\n", l.Addr().String())
klog.Fatal(server.ServeOnListener(l))
return nil
return server.ServeOnListener(l)
}