Extract RESTHandler and allow API groupings

Prepare for running multiple API versions on the same HTTP server
by decoupling some of the mechanics of apiserver.  Define a new
APIGroup object which represents a version of the API.
This commit is contained in:
Clayton Coleman
2014-08-09 17:12:55 -04:00
parent aeea1b1e06
commit bbf3b55e76
10 changed files with 340 additions and 290 deletions

View File

@@ -139,21 +139,11 @@ func (m *Master) init(cloud cloudprovider.Interface, podInfoGetter client.PodInf
}
}
// Run begins serving the Kubernetes API. It never returns.
func (m *Master) Run(myAddress, apiPrefix string) error {
s := &http.Server{
Addr: myAddress,
Handler: m.ConstructHandler(apiPrefix),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
// API_v1beta1 returns the resources and codec for API version v1beta1
func (m *Master) API_v1beta1() (map[string]apiserver.RESTStorage, apiserver.Codec) {
storage := make(map[string]apiserver.RESTStorage)
for k, v := range m.storage {
storage[k] = v
}
return s.ListenAndServe()
}
// ConstructHandler returns an http.Handler which serves the Kubernetes API.
// Instead of calling Run, you can call this function to get a handler for your own server.
// It is intended for testing. Only call once.
func (m *Master) ConstructHandler(apiPrefix string) http.Handler {
return apiserver.New(m.storage, api.Codec, apiPrefix)
return storage, api.Codec
}