Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable API prefix for kubectl proxy #4279

Merged
merged 1 commit into from
Feb 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/kubectl.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Usage:

Available Flags:
--alsologtostderr=false: log to standard error as well as files
--api-prefix="/api/": Prefix to serve the proxied API under
--api-version="": The API version to use when talking to the server
-a, --auth-path="": Path to the auth info file. If missing, prompt the user. Only used if using https.
--certificate-authority="": Path to a cert. file for the certificate authority.
Expand Down
9 changes: 8 additions & 1 deletion pkg/kubectl/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command {
if !strings.HasSuffix(staticPrefix, "/") {
staticPrefix += "/"
}
server, err := kubectl.NewProxyServer(util.GetFlagString(cmd, "www"), staticPrefix, clientConfig)

apiProxyPrefix := util.GetFlagString(cmd, "api-prefix")
if !strings.HasSuffix(apiProxyPrefix, "/") {
apiProxyPrefix += "/"
}
server, err := kubectl.NewProxyServer(util.GetFlagString(cmd, "www"), apiProxyPrefix, staticPrefix, clientConfig)

checkErr(err)
glog.Fatal(server.Serve(port))
},
}
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the specified prefix")
cmd.Flags().StringP("www-prefix", "P", "/static/", "Prefix to serve static files under, if static file dir is specified")
cmd.Flags().StringP("api-prefix", "", "/api/", "Prefix to serve the proxied API under")
cmd.Flags().IntP("port", "p", 8001, "The port on which to run the proxy")
return cmd
}
4 changes: 2 additions & 2 deletions pkg/kubectl/proxy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ProxyServer struct {

// NewProxyServer creates and installs a new ProxyServer.
// It automatically registers the created ProxyServer to http.DefaultServeMux.
func NewProxyServer(filebase string, staticPrefix string, cfg *client.Config) (*ProxyServer, error) {
func NewProxyServer(filebase string, apiProxyPrefix string, staticPrefix string, cfg *client.Config) (*ProxyServer, error) {
prefix := cfg.Prefix
if prefix == "" {
prefix = "/api"
Expand All @@ -46,7 +46,7 @@ func NewProxyServer(filebase string, staticPrefix string, cfg *client.Config) (*
if proxy.Transport, err = client.TransportFor(cfg); err != nil {
return nil, err
}
http.Handle("/api/", http.StripPrefix("/api/", proxy))
http.Handle(apiProxyPrefix, http.StripPrefix(apiProxyPrefix, proxy))
http.Handle(staticPrefix, newFileHandler(staticPrefix, filebase))
return proxy, nil
}
Expand Down