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, ":".
This commit is contained in:
Odin Ugedal 2019-07-26 20:06:46 +02:00
parent 1bb68a2cde
commit 1e50bc2d09
No known key found for this signature in database
GPG Key ID: AFF9C8242CF7A7AF
2 changed files with 6 additions and 4 deletions

View File

@ -103,7 +103,6 @@ vendor/k8s.io/kubectl/pkg/cmd/config
vendor/k8s.io/kubectl/pkg/cmd/edit
vendor/k8s.io/kubectl/pkg/cmd/exec
vendor/k8s.io/kubectl/pkg/cmd/get
vendor/k8s.io/kubectl/pkg/cmd/proxy
vendor/k8s.io/kubectl/pkg/cmd/rollingupdate
vendor/k8s.io/kubectl/pkg/cmd/scale
vendor/k8s.io/kubectl/pkg/cmd/set

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)
}