From 7a909e574ebc49adcf9a95f74a0c2737a8b6549c Mon Sep 17 00:00:00 2001 From: hongming Date: Thu, 7 Nov 2019 21:09:24 +0800 Subject: [PATCH] support node status filter --- pkg/models/resources/nodes.go | 34 +++++++++++++++++++++++++++++++ pkg/models/resources/resources.go | 2 ++ 2 files changed, 36 insertions(+) diff --git a/pkg/models/resources/nodes.go b/pkg/models/resources/nodes.go index b7d99288..10887cda 100644 --- a/pkg/models/resources/nodes.go +++ b/pkg/models/resources/nodes.go @@ -37,6 +37,36 @@ func (*nodeSearcher) get(namespace, name string) (interface{}, error) { return informers.SharedInformerFactory().Core().V1().Nodes().Lister().Get(name) } +func getNodeStatus(node *v1.Node) string { + if node.Spec.Unschedulable { + return StatusUnschedulable + } + for _, condition := range node.Status.Conditions { + if isUnhealthStatus(condition) { + return StatusWarning + } + } + + return StatusRunning +} + +const NodeConfigOK v1.NodeConditionType = "ConfigOK" +const NodeKubeletReady v1.NodeConditionType = "KubeletReady" + +var expectedConditions = map[v1.NodeConditionType]v1.ConditionStatus{v1.NodeOutOfDisk: v1.ConditionFalse, + 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 isUnhealthStatus(condition v1.NodeCondition) bool { + expectedStatus := expectedConditions[condition.Type] + if expectedStatus != "" && condition.Status != expectedStatus { + return true + } + return false +} + // exactly Match func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool { for k, v := range match { @@ -51,6 +81,10 @@ func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool { if _, ok := item.Labels[labelKey]; !ok { return false } + case Status: + if getNodeStatus(item) != v { + return false + } case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false diff --git a/pkg/models/resources/resources.go b/pkg/models/resources/resources.go index 42a8ebda..c1186648 100644 --- a/pkg/models/resources/resources.go +++ b/pkg/models/resources/resources.go @@ -90,6 +90,8 @@ const ( StatusBound = "bound" StatusLost = "lost" StatusComplete = "complete" + StatusWarning = "warning" + StatusUnschedulable = "unschedulable" app = "app" Deployments = "deployments" DaemonSets = "daemonsets" -- GitLab