mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Fix kubectl proxy
Port flag was being ignored. Fixed now.
This commit is contained in:
parent
bba01c7a54
commit
6e98ce34ca
@ -36,9 +36,9 @@ func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command {
|
|||||||
clientConfig, err := f.ClientConfig(cmd)
|
clientConfig, err := f.ClientConfig(cmd)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
server, err := kubectl.NewProxyServer(GetFlagString(cmd, "www"), clientConfig, port)
|
server, err := kubectl.NewProxyServer(GetFlagString(cmd, "www"), clientConfig)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
glog.Fatal(server.Serve())
|
glog.Fatal(server.Serve(port))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the prefix /static")
|
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the prefix /static")
|
||||||
|
@ -29,12 +29,11 @@ import (
|
|||||||
// ProxyServer is a http.Handler which proxies Kubernetes APIs to remote API server.
|
// ProxyServer is a http.Handler which proxies Kubernetes APIs to remote API server.
|
||||||
type ProxyServer struct {
|
type ProxyServer struct {
|
||||||
httputil.ReverseProxy
|
httputil.ReverseProxy
|
||||||
Port int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProxyServer creates and installs a new ProxyServer.
|
// NewProxyServer creates and installs a new ProxyServer.
|
||||||
// It automatically registers the created ProxyServer to http.DefaultServeMux.
|
// It automatically registers the created ProxyServer to http.DefaultServeMux.
|
||||||
func NewProxyServer(filebase string, cfg *client.Config, port int) (*ProxyServer, error) {
|
func NewProxyServer(filebase string, cfg *client.Config) (*ProxyServer, error) {
|
||||||
prefix := cfg.Prefix
|
prefix := cfg.Prefix
|
||||||
if prefix == "" {
|
if prefix == "" {
|
||||||
prefix = "/api"
|
prefix = "/api"
|
||||||
@ -52,9 +51,9 @@ func NewProxyServer(filebase string, cfg *client.Config, port int) (*ProxyServer
|
|||||||
return proxy, nil
|
return proxy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve starts the server (http.DefaultServeMux) on TCP port 8001, loops forever.
|
// Serve starts the server (http.DefaultServeMux) on given port, loops forever.
|
||||||
func (s *ProxyServer) Serve() error {
|
func (s *ProxyServer) Serve(port int) error {
|
||||||
addr := fmt.Sprintf(":%d", s.Port)
|
addr := fmt.Sprintf(":%d", port)
|
||||||
return http.ListenAndServe(addr, nil)
|
return http.ListenAndServe(addr, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user