fix: node status filter

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2020-07-16 12:08:44 +08:00
parent de5f4c36e0
commit 4f3007c143
2 changed files with 161 additions and 8 deletions

View File

@@ -31,14 +31,19 @@ import (
// Those annotations were added to node only for display purposes
const (
nodeCPURequests = "node.kubesphere.io/cpu-requests"
nodeMemoryRequests = "node.kubesphere.io/memory-requests"
nodeCPULimits = "node.kubesphere.io/cpu-limits"
nodeMemoryLimits = "node.kubesphere.io/memory-limits"
nodeCPURequestsFraction = "node.kubesphere.io/cpu-requests-fraction"
nodeCPULimitsFraction = "node.kubesphere.io/cpu-limits-fraction"
nodeMemoryRequestsFraction = "node.kubesphere.io/memory-requests-fraction"
nodeMemoryLimitsFraction = "node.kubesphere.io/memory-limits-fraction"
nodeCPURequests = "node.kubesphere.io/cpu-requests"
nodeMemoryRequests = "node.kubesphere.io/memory-requests"
nodeCPULimits = "node.kubesphere.io/cpu-limits"
nodeMemoryLimits = "node.kubesphere.io/memory-limits"
nodeCPURequestsFraction = "node.kubesphere.io/cpu-requests-fraction"
nodeCPULimitsFraction = "node.kubesphere.io/cpu-limits-fraction"
nodeMemoryRequestsFraction = "node.kubesphere.io/memory-requests-fraction"
nodeMemoryLimitsFraction = "node.kubesphere.io/memory-limits-fraction"
nodeConfigOK v1.NodeConditionType = "ConfigOK"
nodeKubeletReady v1.NodeConditionType = "KubeletReady"
statusRunning = "running"
statusWarning = "warning"
statusUnschedulable = "unschedulable"
)
type nodesGetter struct {
@@ -107,6 +112,10 @@ func (c nodesGetter) filter(object runtime.Object, filter query.Filter) bool {
if !ok {
return false
}
switch filter.Field {
case query.FieldStatus:
return getNodeStatus(node) == string(filter.Value)
}
return v1alpha3.DefaultObjectMetaFilter(node.ObjectMeta, filter)
}
@@ -177,3 +186,34 @@ func (c nodesGetter) getPodsTotalRequestAndLimits(pods []*v1.Pod) (reqs map[v1.R
}
return
}
func getNodeStatus(node *v1.Node) string {
if node.Spec.Unschedulable {
return statusUnschedulable
}
for _, condition := range node.Status.Conditions {
if isUnhealthyStatus(condition) {
return statusWarning
}
}
return statusRunning
}
var expectedConditions = map[v1.NodeConditionType]v1.ConditionStatus{
v1.NodeMemoryPressure: v1.ConditionFalse,
v1.NodeDiskPressure: v1.ConditionFalse,
v1.NodePIDPressure: v1.ConditionFalse,
v1.NodeNetworkUnavailable: v1.ConditionFalse,
nodeConfigOK: v1.ConditionTrue,
nodeKubeletReady: v1.ConditionTrue,
v1.NodeReady: v1.ConditionTrue,
}
func isUnhealthyStatus(condition v1.NodeCondition) bool {
expectedStatus := expectedConditions[condition.Type]
if expectedStatus != "" && condition.Status != expectedStatus {
return true
}
return false
}