Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3ae67f81
Commit
3ae67f81
authored
Jan 21, 2015
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3548 from nikhiljindal/listHandlers
Updating handleIndex in master to list all valid paths.
parents
838dfde0
51007cc7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
21 deletions
+77
-21
unversioned.go
pkg/api/unversioned.go
+6
-0
apiserver.go
pkg/apiserver/apiserver.go
+5
-7
index.go
pkg/apiserver/index.go
+17
-4
mux_helper.go
pkg/apiserver/mux_helper.go
+37
-0
master.go
pkg/master/master.go
+12
-10
No files found.
pkg/api/unversioned.go
View file @
3ae67f81
...
@@ -24,3 +24,9 @@ package api
...
@@ -24,3 +24,9 @@ package api
type
APIVersions
struct
{
type
APIVersions
struct
{
Versions
[]
string
`json:"versions"`
Versions
[]
string
`json:"versions"`
}
}
// RootPaths lists the paths available at root.
// For example: "/healthz", "/api".
type
RootPaths
struct
{
Paths
[]
string
`json:"paths"`
}
pkg/apiserver/apiserver.go
View file @
3ae67f81
...
@@ -62,9 +62,9 @@ func Handle(storage map[string]RESTStorage, codec runtime.Codec, root string, ve
...
@@ -62,9 +62,9 @@ func Handle(storage map[string]RESTStorage, codec runtime.Codec, root string, ve
group
:=
NewAPIGroupVersion
(
storage
,
codec
,
prefix
,
selfLinker
,
admissionControl
)
group
:=
NewAPIGroupVersion
(
storage
,
codec
,
prefix
,
selfLinker
,
admissionControl
)
container
:=
restful
.
NewContainer
()
container
:=
restful
.
NewContainer
()
mux
:=
container
.
ServeMux
mux
:=
container
.
ServeMux
group
.
InstallREST
(
container
,
root
,
version
)
group
.
InstallREST
(
container
,
mux
,
root
,
version
)
ws
:=
new
(
restful
.
WebService
)
ws
:=
new
(
restful
.
WebService
)
InstallSupport
(
container
,
ws
)
InstallSupport
(
mux
,
ws
)
container
.
Add
(
ws
)
container
.
Add
(
ws
)
return
&
defaultAPIServer
{
mux
,
group
}
return
&
defaultAPIServer
{
mux
,
group
}
}
}
...
@@ -203,7 +203,7 @@ func addParamIf(b *restful.RouteBuilder, parameter *restful.Parameter, shouldAdd
...
@@ -203,7 +203,7 @@ func addParamIf(b *restful.RouteBuilder, parameter *restful.Parameter, shouldAdd
// InstallREST registers the REST handlers (storage, watch, and operations) into a restful Container.
// InstallREST registers the REST handlers (storage, watch, and operations) into a restful Container.
// It is expected that the provided path root prefix will serve all operations. Root MUST NOT end
// It is expected that the provided path root prefix will serve all operations. Root MUST NOT end
// in a slash. A restful WebService is created for the group and version.
// in a slash. A restful WebService is created for the group and version.
func
(
g
*
APIGroupVersion
)
InstallREST
(
container
*
restful
.
Container
,
root
string
,
version
string
)
error
{
func
(
g
*
APIGroupVersion
)
InstallREST
(
container
*
restful
.
Container
,
mux
Mux
,
root
string
,
version
string
)
error
{
prefix
:=
path
.
Join
(
root
,
version
)
prefix
:=
path
.
Join
(
root
,
version
)
restHandler
:=
&
g
.
handler
restHandler
:=
&
g
.
handler
strippedHandler
:=
http
.
StripPrefix
(
prefix
,
restHandler
)
strippedHandler
:=
http
.
StripPrefix
(
prefix
,
restHandler
)
...
@@ -268,8 +268,6 @@ func (g *APIGroupVersion) InstallREST(container *restful.Container, root string,
...
@@ -268,8 +268,6 @@ func (g *APIGroupVersion) InstallREST(container *restful.Container, root string,
// TODO: port the rest of these. Sadly, if we don't, we'll have inconsistent
// TODO: port the rest of these. Sadly, if we don't, we'll have inconsistent
// API behavior, as well as lack of documentation
// API behavior, as well as lack of documentation
mux
:=
container
.
ServeMux
// Note: update GetAttribs() when adding a handler.
// Note: update GetAttribs() when adding a handler.
mux
.
Handle
(
prefix
+
"/watch/"
,
http
.
StripPrefix
(
prefix
+
"/watch/"
,
watchHandler
))
mux
.
Handle
(
prefix
+
"/watch/"
,
http
.
StripPrefix
(
prefix
+
"/watch/"
,
watchHandler
))
mux
.
Handle
(
prefix
+
"/proxy/"
,
http
.
StripPrefix
(
prefix
+
"/proxy/"
,
proxyHandler
))
mux
.
Handle
(
prefix
+
"/proxy/"
,
http
.
StripPrefix
(
prefix
+
"/proxy/"
,
proxyHandler
))
...
@@ -296,9 +294,9 @@ func InstallValidator(mux Mux, servers func() map[string]Server) {
...
@@ -296,9 +294,9 @@ func InstallValidator(mux Mux, servers func() map[string]Server) {
// TODO: document all handlers
// TODO: document all handlers
// InstallSupport registers the APIServer support functions
// InstallSupport registers the APIServer support functions
func
InstallSupport
(
container
*
restful
.
Container
,
ws
*
restful
.
WebService
)
{
func
InstallSupport
(
mux
Mux
,
ws
*
restful
.
WebService
)
{
// TODO: convert healthz to restful and remove container arg
// TODO: convert healthz to restful and remove container arg
healthz
.
InstallHandler
(
container
.
ServeM
ux
)
healthz
.
InstallHandler
(
m
ux
)
// Set up a service to return the git code version.
// Set up a service to return the git code version.
ws
.
Path
(
"/version"
)
ws
.
Path
(
"/version"
)
...
...
pkg/apiserver/index.go
View file @
3ae67f81
...
@@ -17,11 +17,24 @@ limitations under the License.
...
@@ -17,11 +17,24 @@ limitations under the License.
package
apiserver
package
apiserver
import
(
import
(
"io"
"net/http"
"net/http"
"sort"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/emicklei/go-restful"
)
)
// handleIndex is the root index page for Kubernetes.
func
IndexHandler
(
container
*
restful
.
Container
,
muxHelper
*
MuxHelper
)
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
func
HandleIndex
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
io
.
WriteString
(
w
,
"<html><body>Welcome to Kubernetes</body></html>"
)
var
handledPaths
[]
string
// Extract the paths handled using restful.WebService
for
_
,
ws
:=
range
container
.
RegisteredWebServices
()
{
handledPaths
=
append
(
handledPaths
,
ws
.
RootPath
())
}
// Extract the paths handled using mux handler.
handledPaths
=
append
(
handledPaths
,
muxHelper
.
RegisteredPaths
...
)
sort
.
Strings
(
handledPaths
)
writeRawJSON
(
http
.
StatusOK
,
api
.
RootPaths
{
Paths
:
handledPaths
},
w
)
}
}
}
pkg/apiserver/mux_helper.go
0 → 100644
View file @
3ae67f81
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
apiserver
import
(
"net/http"
)
// Offers additional functionality over ServeMux, for ex: supports listing registered paths.
type
MuxHelper
struct
{
Mux
Mux
RegisteredPaths
[]
string
}
func
(
m
*
MuxHelper
)
Handle
(
path
string
,
handler
http
.
Handler
)
{
m
.
RegisteredPaths
=
append
(
m
.
RegisteredPaths
,
path
)
m
.
Mux
.
Handle
(
path
,
handler
)
}
func
(
m
*
MuxHelper
)
HandleFunc
(
path
string
,
handler
func
(
http
.
ResponseWriter
,
*
http
.
Request
))
{
m
.
RegisteredPaths
=
append
(
m
.
RegisteredPaths
,
path
)
m
.
Mux
.
HandleFunc
(
path
,
handler
)
}
pkg/master/master.go
View file @
3ae67f81
...
@@ -114,6 +114,7 @@ type Master struct {
...
@@ -114,6 +114,7 @@ type Master struct {
portalNet
*
net
.
IPNet
portalNet
*
net
.
IPNet
mux
apiserver
.
Mux
mux
apiserver
.
Mux
muxHelper
*
apiserver
.
MuxHelper
handlerContainer
*
restful
.
Container
handlerContainer
*
restful
.
Container
rootWebService
*
restful
.
WebService
rootWebService
*
restful
.
WebService
enableLogsSupport
bool
enableLogsSupport
bool
...
@@ -274,6 +275,7 @@ func New(c *Config) *Master {
...
@@ -274,6 +275,7 @@ func New(c *Config) *Master {
m
.
mux
=
mux
m
.
mux
=
mux
m
.
handlerContainer
=
NewHandlerContainer
(
mux
)
m
.
handlerContainer
=
NewHandlerContainer
(
mux
)
}
}
m
.
muxHelper
=
&
apiserver
.
MuxHelper
{
m
.
mux
,
[]
string
{}}
m
.
masterServices
=
util
.
NewRunner
(
m
.
serviceWriterLoop
,
m
.
roServiceWriterLoop
)
m
.
masterServices
=
util
.
NewRunner
(
m
.
serviceWriterLoop
,
m
.
roServiceWriterLoop
)
m
.
init
(
c
)
m
.
init
(
c
)
...
@@ -289,7 +291,7 @@ func (m *Master) HandleWithAuth(pattern string, handler http.Handler) {
...
@@ -289,7 +291,7 @@ func (m *Master) HandleWithAuth(pattern string, handler http.Handler) {
// sensible policy defaults for plugged-in endpoints. This will be different
// sensible policy defaults for plugged-in endpoints. This will be different
// for generic endpoints versus REST object endpoints.
// for generic endpoints versus REST object endpoints.
// TODO: convert to go-restful
// TODO: convert to go-restful
m
.
mux
.
Handle
(
pattern
,
handler
)
m
.
mux
Helper
.
Handle
(
pattern
,
handler
)
}
}
// HandleFuncWithAuth adds an http.Handler for pattern to an http.ServeMux
// HandleFuncWithAuth adds an http.Handler for pattern to an http.ServeMux
...
@@ -297,7 +299,7 @@ func (m *Master) HandleWithAuth(pattern string, handler http.Handler) {
...
@@ -297,7 +299,7 @@ func (m *Master) HandleWithAuth(pattern string, handler http.Handler) {
// to the request is used for the master's built-in endpoints.
// to the request is used for the master's built-in endpoints.
func
(
m
*
Master
)
HandleFuncWithAuth
(
pattern
string
,
handler
func
(
http
.
ResponseWriter
,
*
http
.
Request
))
{
func
(
m
*
Master
)
HandleFuncWithAuth
(
pattern
string
,
handler
func
(
http
.
ResponseWriter
,
*
http
.
Request
))
{
// TODO: convert to go-restful
// TODO: convert to go-restful
m
.
mux
.
HandleFunc
(
pattern
,
handler
)
m
.
mux
Helper
.
HandleFunc
(
pattern
,
handler
)
}
}
func
NewHandlerContainer
(
mux
*
http
.
ServeMux
)
*
restful
.
Container
{
func
NewHandlerContainer
(
mux
*
http
.
ServeMux
)
*
restful
.
Container
{
...
@@ -362,33 +364,33 @@ func (m *Master) init(c *Config) {
...
@@ -362,33 +364,33 @@ func (m *Master) init(c *Config) {
}
}
apiVersions
:=
[]
string
{
"v1beta1"
,
"v1beta2"
}
apiVersions
:=
[]
string
{
"v1beta1"
,
"v1beta2"
}
if
err
:=
apiserver
.
NewAPIGroupVersion
(
m
.
api_v1beta1
())
.
InstallREST
(
m
.
handlerContainer
,
c
.
APIPrefix
,
"v1beta1"
);
err
!=
nil
{
if
err
:=
apiserver
.
NewAPIGroupVersion
(
m
.
api_v1beta1
())
.
InstallREST
(
m
.
handlerContainer
,
m
.
muxHelper
,
c
.
APIPrefix
,
"v1beta1"
);
err
!=
nil
{
glog
.
Fatalf
(
"Unable to setup API v1beta1: %v"
,
err
)
glog
.
Fatalf
(
"Unable to setup API v1beta1: %v"
,
err
)
}
}
if
err
:=
apiserver
.
NewAPIGroupVersion
(
m
.
api_v1beta2
())
.
InstallREST
(
m
.
handlerContainer
,
c
.
APIPrefix
,
"v1beta2"
);
err
!=
nil
{
if
err
:=
apiserver
.
NewAPIGroupVersion
(
m
.
api_v1beta2
())
.
InstallREST
(
m
.
handlerContainer
,
m
.
muxHelper
,
c
.
APIPrefix
,
"v1beta2"
);
err
!=
nil
{
glog
.
Fatalf
(
"Unable to setup API v1beta2: %v"
,
err
)
glog
.
Fatalf
(
"Unable to setup API v1beta2: %v"
,
err
)
}
}
if
c
.
EnableV1Beta3
{
if
c
.
EnableV1Beta3
{
if
err
:=
apiserver
.
NewAPIGroupVersion
(
m
.
api_v1beta3
())
.
InstallREST
(
m
.
handlerContainer
,
c
.
APIPrefix
,
"v1beta3"
);
err
!=
nil
{
if
err
:=
apiserver
.
NewAPIGroupVersion
(
m
.
api_v1beta3
())
.
InstallREST
(
m
.
handlerContainer
,
m
.
muxHelper
,
c
.
APIPrefix
,
"v1beta3"
);
err
!=
nil
{
glog
.
Fatalf
(
"Unable to setup API v1beta3: %v"
,
err
)
glog
.
Fatalf
(
"Unable to setup API v1beta3: %v"
,
err
)
}
}
apiVersions
=
[]
string
{
"v1beta1"
,
"v1beta2"
,
"v1beta3"
}
apiVersions
=
[]
string
{
"v1beta1"
,
"v1beta2"
,
"v1beta3"
}
}
}
apiserver
.
InstallSupport
(
m
.
handlerContain
er
,
m
.
rootWebService
)
apiserver
.
InstallSupport
(
m
.
muxHelp
er
,
m
.
rootWebService
)
apiserver
.
AddApiWebService
(
m
.
handlerContainer
,
c
.
APIPrefix
,
apiVersions
)
apiserver
.
AddApiWebService
(
m
.
handlerContainer
,
c
.
APIPrefix
,
apiVersions
)
// Register root handler.
// Register root handler.
// We do not register this using restful Webservice since we do not want to surface this in api docs.
// We do not register this using restful Webservice since we do not want to surface this in api docs.
m
.
mux
.
HandleFunc
(
"/"
,
apiserver
.
HandleIndex
)
m
.
mux
.
HandleFunc
(
"/"
,
apiserver
.
IndexHandler
(
m
.
handlerContainer
,
m
.
muxHelper
)
)
// TODO: use go-restful
// TODO: use go-restful
apiserver
.
InstallValidator
(
m
.
mux
,
func
()
map
[
string
]
apiserver
.
Server
{
return
m
.
getServersToValidate
(
c
)
})
apiserver
.
InstallValidator
(
m
.
mux
Helper
,
func
()
map
[
string
]
apiserver
.
Server
{
return
m
.
getServersToValidate
(
c
)
})
if
c
.
EnableLogsSupport
{
if
c
.
EnableLogsSupport
{
apiserver
.
InstallLogsSupport
(
m
.
mux
)
apiserver
.
InstallLogsSupport
(
m
.
mux
Helper
)
}
}
if
c
.
EnableUISupport
{
if
c
.
EnableUISupport
{
ui
.
InstallSupport
(
m
.
mux
,
m
.
enableSwaggerSupport
)
ui
.
InstallSupport
(
m
.
mux
Helper
,
m
.
enableSwaggerSupport
)
}
}
// TODO: install runtime/pprof handler
// TODO: install runtime/pprof handler
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment