[REV] update node os info and label info

This commit is contained in:
barnett 2018-12-08 19:33:44 +08:00
parent 208c9c7480
commit d581457485
2 changed files with 25 additions and 14 deletions

View File

@ -75,6 +75,9 @@ func (e *etcdClusterClient) UpdateStatus(n *HostNode) error {
existNode.NodeStatus.Version = cmd.GetVersion()
existNode.NodeStatus.AdviceAction = n.NodeStatus.AdviceAction
existNode.NodeStatus.Status = n.NodeStatus.Status
if existNode.NodeStatus.NodeInfo.OperatingSystem == "" {
existNode.NodeStatus.NodeInfo = n.NodeStatus.NodeInfo
}
existNode.UpdataCondition(n.NodeStatus.Conditions...)
return e.Update(existNode)
}

View File

@ -272,10 +272,31 @@ func (n *NodeManager) init() error {
return fmt.Errorf("find node %s from cluster failure %s", n.currentNode.ID, err.Error())
}
}
n.setNodeLabels(node)
if node.NodeStatus.NodeInfo.OperatingSystem == "" {
node.NodeStatus.NodeInfo = info.GetSystemInfo()
}
*n.currentNode = *node
return nil
}
func (n *NodeManager) setNodeLabels(node *client.HostNode) {
node.Role = strings.Split(n.cfg.NodeRule, ",")
if node.Labels == nil || len(node.Labels) < 1 {
node.Labels = map[string]string{}
}
for _, rule := range node.Role {
node.Labels["rainbond_node_rule_"+rule] = "true"
}
node.Labels[client.LabelOS] = runtime.GOOS
hostname, _ := os.Hostname()
if node.HostName != hostname && hostname != "" {
node.HostName = hostname
}
node.Labels["rainbond_node_hostname"] = node.HostName
node.Labels["rainbond_node_ip"] = node.InternalIP
}
//getCurrentNode get current node info
func (n *NodeManager) getCurrentNode(uid string) (*client.HostNode, error) {
if n.cfg.HostIP == "" {
@ -286,21 +307,8 @@ func (n *NodeManager) getCurrentNode(uid string) (*client.HostNode, error) {
n.cfg.HostIP = ip.String()
}
node := CreateNode(uid, n.cfg.HostIP)
n.setNodeLabels(&node)
node.NodeStatus.NodeInfo = info.GetSystemInfo()
node.Role = strings.Split(n.cfg.NodeRule, ",")
if node.Labels == nil || len(node.Labels) < 1 {
node.Labels = map[string]string{}
}
for _, rule := range node.Role {
node.Labels["rainbond_node_rule_"+rule] = "true"
}
node.Labels[client.LabelOS] = runtime.GOOS
if node.HostName == "" {
hostname, _ := os.Hostname()
node.HostName = hostname
}
node.Labels["rainbond_node_hostname"] = node.HostName
node.Labels["rainbond_node_ip"] = node.InternalIP
node.UpdataCondition(client.NodeCondition{
Type: client.NodeInit,
Status: client.ConditionTrue,