[REV] update node monitor code

This commit is contained in:
barnett 2018-05-11 16:54:23 +08:00
parent 305c5eb92f
commit 25e2196a17
5 changed files with 27 additions and 22 deletions

View File

@ -18,22 +18,6 @@
package exector
/*
Copyright 2017 The Goodrain Authors.
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.
*/
import (
"fmt"
"strings"

View File

@ -109,6 +109,8 @@ func handleStatus(v *model.HostNode) {
}
}
}
} else {
v.Status = "down"
}
if v.Role.HasRule("manage") { //manage install_success == runnint
if v.Status == "init" || v.Status == "init_success" || v.Status == "init_failed" || v.Status == "installing" || v.Status == "install_failed" {

View File

@ -79,6 +79,7 @@ type HostNode struct {
}
type NodeList []*HostNode
func (list NodeList) Len() int {
return len(list)
}
@ -96,7 +97,9 @@ func (list NodeList) Swap(i, j int) {
list[i] = list[j]
list[j] = temp
}
type TaskResult []*ExecedTask
func (c TaskResult) Len() int {
return len(c)
}
@ -104,11 +107,11 @@ func (c TaskResult) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
func (c TaskResult) Less(i, j int) bool {
if c[i].Status == "complete"&&(c[j].Status=="start"||c[j].Status=="wait") {
if c[i].Status == "complete" && (c[j].Status == "start" || c[j].Status == "wait") {
return true
}
if c[i].Status=="start" {
if c[j].Status=="complete" {
if c[i].Status == "start" {
if c[j].Status == "complete" {
return false
}
if c[j].Status == "wait" {
@ -116,11 +119,12 @@ func (c TaskResult) Less(i, j int) bool {
}
return true
}
if c[i].Status=="wait" {
if c[i].Status == "wait" {
return false
}
return true
}
//GetNodeFromKV 从etcd解析node信息
func GetNodeFromKV(kv *mvccpb.KeyValue) *HostNode {
var node HostNode
@ -146,6 +150,17 @@ func (h *HostNode) UpdataK8sCondition(conditions []v1.NodeCondition) {
}
}
//DeleteCondition DeleteCondition
func (h *HostNode) DeleteCondition(types ...NodeConditionType) {
for i, c := range h.Conditions {
for _, t := range types {
if c.Type.Compare(t) {
h.Conditions = append(h.Conditions[:i], h.Conditions[i+1:]...)
}
}
}
}
//UpdataCondition 更新状态
func (h *HostNode) UpdataCondition(conditions ...NodeCondition) {
var ready = ConditionTrue
@ -215,7 +230,10 @@ const (
// InstallNotReady means the installation task was not completed in this node.
InstallNotReady NodeConditionType = "InstallNotReady"
// NodeInit means node already install rainbond node and regist
NodeInit NodeConditionType = "NodeInit"
NodeInit NodeConditionType = "NodeInit"
OutOfDisk NodeConditionType = "OutOfDisk"
MemoryPressure NodeConditionType = "MemoryPressure"
DiskPressure NodeConditionType = "DiskPressure"
)
//Compare 比较

View File

@ -172,11 +172,11 @@ 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()))
}
hostNode.Status = "down"
hostNode.NodeStatus = nil
n.nodecluster.UpdateNode(hostNode)
return hostNode, nil

View File

@ -318,6 +318,7 @@ func (n *NodeCluster) loadAndWatchK8sNodes() {
if node, ok := event.Object.(*v1.Node); ok {
if rbnode := n.GetNode(node.Name); rbnode != nil {
rbnode.NodeStatus = nil
rbnode.DeleteCondition(model.NodeReady, model.OutOfDisk, model.MemoryPressure, model.DiskPressure)
n.UpdateNode(rbnode)
}
}