[REV] optimize node status

This commit is contained in:
bay1ts 2017-12-07 14:53:40 +08:00
parent 84b34ea2e9
commit 661676382d
3 changed files with 21 additions and 0 deletions

View File

@ -76,6 +76,15 @@ func GetNodes(w http.ResponseWriter, r *http.Request) {
err.Handle(r, w)
return
}
for _,v:=range nodes {
if v.NodeStatus!=nil{
for _,v:=range v.Conditions{
if v.Type=="Ready"&&v.Status=="True" {
v.Status="running"
}
}
}
}
httputil.ReturnSuccess(r, w, nodes)
}

View File

@ -78,11 +78,21 @@ func ExecTask(w http.ResponseWriter, r *http.Request) {
if ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &nodes, nil); !ok {
return
}
err := taskService.ExecTask(taskID, nodes.Nodes)
if err != nil {
err.Handle(r, w)
return
}
for _,v:=range nodes.Nodes {
node, err := nodeService.GetNode(v)
if err != nil {
err.Handle(r, w)
return
}
node.Status="install"
}
httputil.ReturnSuccess(r, w, nil)
}

View File

@ -62,6 +62,7 @@ func (n *NodeService) AddNode(node *model.APIHostNode) *utils.APIHandleError {
}
}
rbnode := node.Clone()
rbnode.Status="init"
rbnode.CreateTime = time.Now()
rbnode.Conditions = make([]model.NodeCondition, 0)
if _, err := rbnode.Update(); err != nil {
@ -163,6 +164,7 @@ func (n *NodeService) DownNode(nodeID string) (*model.HostNode, *utils.APIHandle
if !hostNode.Role.HasRule(model.ComputeNode) || hostNode.NodeStatus == nil {
return nil, utils.CreateAPIHandleError(400, fmt.Errorf("node is not k8s node or it not up"))
}
hostNode.Status="down"
err := k8s.DeleteNode(hostNode.ID)
if err != nil {
return nil, utils.CreateAPIHandleError(500, fmt.Errorf("k8s node down error,%s", err.Error()))