Skip to content

Commit

Permalink
determine node roles based on their labels (#4089)
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Oct 22, 2023
1 parent 7bccea7 commit f77579d
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/helmvm/helmvm_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ func nodeMetrics(ctx context.Context, client kubernetes.Interface, metricsClient

podCapacity.Used = float64(len(nodePods))

nodeLabelArray := []string{}
for k, v := range node.Labels {
nodeLabelArray = append(nodeLabelArray, fmt.Sprintf("%s:%s", k, v))
}

podInfo := []types.PodInfo{}

for _, pod := range nodePods {
Expand Down Expand Up @@ -135,8 +130,23 @@ func nodeMetrics(ctx context.Context, client kubernetes.Interface, metricsClient
CPU: cpuCapacity,
Memory: memoryCapacity,
Pods: podCapacity,
Labels: nodeLabelArray,
Labels: nodeRolesFromLabels(node.Labels),
Conditions: findNodeConditions(node.Status.Conditions),
PodList: podInfo,
}, nil
}

func nodeRolesFromLabels(labels map[string]string) []string {
toReturn := []string{}

// detect if this is a controller node from the k8s labels
if val, ok := labels["node-role.kubernetes.io/control-plane"]; ok && val == "true" {
toReturn = append(toReturn, "controller")
}

if len(toReturn) == 0 {
toReturn = append(toReturn, "worker")
}

return toReturn
}

0 comments on commit f77579d

Please sign in to comment.