From d58145748529bc3d4f22733143f960eb532987ca Mon Sep 17 00:00:00 2001 From: barnett <576501057@qq.com> Date: Sat, 8 Dec 2018 19:33:44 +0800 Subject: [PATCH] [REV] update node os info and label info --- node/nodem/client/cluster_client.go | 3 +++ node/nodem/node_manager.go | 36 ++++++++++++++++++----------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/node/nodem/client/cluster_client.go b/node/nodem/client/cluster_client.go index c30a562a7..eca58dd47 100644 --- a/node/nodem/client/cluster_client.go +++ b/node/nodem/client/cluster_client.go @@ -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) } diff --git a/node/nodem/node_manager.go b/node/nodem/node_manager.go index a9c0b50d7..aa35dfbf1 100644 --- a/node/nodem/node_manager.go +++ b/node/nodem/node_manager.go @@ -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,