[ADD] Merging three k8s metrics into kubelet

This commit is contained in:
zhoujunhao 2018-11-02 17:36:06 +08:00
parent 1f25c7c216
commit a124016df0
2 changed files with 35 additions and 9 deletions

View File

@ -38,15 +38,15 @@ import (
)
const (
Running = "running"
Offline = "offline"
Unknown = "unknown"
Error = "error"
Init = "init"
Running = "running"
Offline = "offline"
Unknown = "unknown"
Error = "error"
Init = "init"
InstallSuccess = "install_success"
InstallFailed = "install_failed"
Installing = "installing"
NotInstalled = "not_installed"
Installing = "installing"
NotInstalled = "not_installed"
)
//NodeService node service
@ -159,7 +159,7 @@ func (n *NodeService) DeleteNode(nodeID string) *utils.APIHandleError {
return utils.CreateAPIHandleError(400, fmt.Errorf("node is online, can not delete"))
}
// TODO:compute node check node is offline
if node.Status != Offline && node.Status != NotInstalled && node.Status != InstallFailed && node.Status != InstallSuccess {
if node.Status != Offline && node.Status != Unknown && node.Status != NotInstalled && node.Status != InstallFailed && node.Status != InstallSuccess && node.Status != Installing {
return utils.CreateAPIHandleError(401, fmt.Errorf("node is not offline"))
}
n.nodecluster.RemoveNode(node.ID)

View File

@ -297,9 +297,25 @@ func (n *Cluster) handleNodeStatus(v *client.HostNode) {
v.UpdataCondition(r)
return
}
//var haveready bool
for _, condiction := range v.NodeStatus.Conditions {
if condiction.Type == "OutOfDisk" || condiction.Type == "MemoryPressure" || condiction.Type == "DiskPressure"{
if condiction.Status == "False"{
v.DeleteCondition(condiction.Type)
}else {
message := n.getKubeletMessage(v)
r := client.NodeCondition{
Type: "kubelet",
Status: client.ConditionFalse,
LastHeartbeatTime: time.Now(),
LastTransitionTime: time.Now(),
Message:message + "/" + condiction.Message,
}
v.UpdataCondition(r)
}
}
if (condiction.Status == "True" || condiction.Status == "Unknown") && (condiction.Type == "OutOfDisk" || condiction.Type == "MemoryPressure" || condiction.Type == "DiskPressure") {
v.Status = status
v.NodeStatus.Status = status
@ -696,3 +712,13 @@ func (n *Cluster) handleNodeHealth(v *client.HostNode) {
}
}
}
func (n *Cluster) getKubeletMessage(v *client.HostNode) string{
for _, condiction := range v.NodeStatus.Conditions {
if condiction.Type == "kubelet"{
return condiction.Message
}
}
return ""
}