fix: node failed to get role (#1535)

Co-authored-by: 曲源成 <quyc@goodrain.com>
This commit is contained in:
Quyc 2023-02-15 20:44:00 +08:00 committed by GitHub
parent 3c83770c82
commit cd4faba222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,8 @@ import (
const (
// NodeRolesLabelPrefix -
NodeRolesLabelPrefix = "node-role.kubernetes.io"
// NodeRolesLabel -
NodeRolesLabel = "kubernetes.io/role"
// NodeInternalIP -
NodeInternalIP = "InternalIP"
// NodeExternalIP -
@ -151,12 +153,16 @@ func (n *nodesHandle) HandleNodeInfo(node v1.Node) (nodeinfo model.NodeInfo, err
}
// get node roles
var roles []string
for k := range node.Labels {
for k, v := range node.Labels {
if strings.HasPrefix(k, NodeRolesLabelPrefix) {
// string handle : node-role.kubernetes.io/worker: "true"
role := strings.Split(k, "/")[1]
roles = append(roles, role)
}
if strings.HasPrefix(k, NodeRolesLabel) {
// string handle : kubernetes.io/role: master
roles = append(roles, v)
}
continue
}
// req resource from Prometheus