Turn on node level validation, and make the validation set dynamic.

This commit is contained in:
Brendan Burns 2014-12-10 22:02:45 -08:00
parent 5523e0344a
commit 59b5546b28
3 changed files with 7 additions and 8 deletions

View File

@ -238,7 +238,7 @@ func (g *APIGroupVersion) InstallREST(container *restful.Container, root string,
} }
// TODO: Convert to go-restful // TODO: Convert to go-restful
func InstallValidator(mux Mux, servers map[string]Server) { func InstallValidator(mux Mux, servers func() map[string]Server) {
validator, err := NewValidator(servers) validator, err := NewValidator(servers)
if err != nil { if err != nil {
glog.Errorf("failed to set up validator: %v", err) glog.Errorf("failed to set up validator: %v", err)

View File

@ -41,7 +41,7 @@ type Server struct {
// validator is responsible for validating the cluster and serving // validator is responsible for validating the cluster and serving
type validator struct { type validator struct {
// a list of servers to health check // a list of servers to health check
servers map[string]Server servers func() map[string]Server
client httpGet client httpGet
} }
@ -72,7 +72,7 @@ type ServerStatus struct {
func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) {
reply := []ServerStatus{} reply := []ServerStatus{}
for name, server := range v.servers { for name, server := range v.servers() {
status, msg, err := server.check(v.client) status, msg, err := server.check(v.client)
var errorMsg string var errorMsg string
if err != nil { if err != nil {
@ -93,7 +93,7 @@ func (v *validator) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// NewValidator creates a validator for a set of servers. // NewValidator creates a validator for a set of servers.
func NewValidator(servers map[string]Server) (http.Handler, error) { func NewValidator(servers func() map[string]Server) (http.Handler, error) {
return &validator{ return &validator{
servers: servers, servers: servers,
client: &http.Client{}, client: &http.Client{},
@ -114,7 +114,7 @@ func makeTestValidator(servers map[string]string, get httpGet) (http.Handler, er
result[name] = Server{Addr: host, Port: val, Path: "/healthz"} result[name] = Server{Addr: host, Port: val, Path: "/healthz"}
} }
v, e := NewValidator(result) v, e := NewValidator(func() map[string]Server { return result })
if e == nil { if e == nil {
v.(*validator).client = get v.(*validator).client = get
} }

View File

@ -339,8 +339,7 @@ func (m *Master) init(c *Config) {
apiserver.InstallSupport(m.handlerContainer, m.rootWebService) apiserver.InstallSupport(m.handlerContainer, m.rootWebService)
// TODO: use go-restful // TODO: use go-restful
serversToValidate := m.getServersToValidate(c) apiserver.InstallValidator(m.mux, func() map[string]apiserver.Server { return m.getServersToValidate(c) })
apiserver.InstallValidator(m.mux, serversToValidate)
if c.EnableLogsSupport { if c.EnableLogsSupport {
apiserver.InstallLogsSupport(m.mux) apiserver.InstallLogsSupport(m.mux)
} }
@ -430,7 +429,7 @@ func (m *Master) getServersToValidate(c *Config) map[string]apiserver.Server {
glog.Errorf("Failed to list minions: %v", err) glog.Errorf("Failed to list minions: %v", err)
} }
for ix, node := range nodes.Items { for ix, node := range nodes.Items {
serversToValidate[fmt.Sprintf("node-%d", ix)] = apiserver.Server{Addr: node.Status.HostIP, Port: 10250, Path: "/healthz"} serversToValidate[fmt.Sprintf("node-%d", ix)] = apiserver.Server{Addr: node.Name, Port: 10250, Path: "/healthz"}
} }
return serversToValidate return serversToValidate
} }