Merge pull request #1418 from wansir/master

support node status filter
This commit is contained in:
KubeSphere CI Bot
2019-11-08 14:47:07 +08:00
committed by GitHub
2 changed files with 36 additions and 0 deletions

View File

@@ -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

View File

@@ -90,6 +90,8 @@ const (
StatusBound = "bound"
StatusLost = "lost"
StatusComplete = "complete"
StatusWarning = "warning"
StatusUnschedulable = "unschedulable"
app = "app"
Deployments = "deployments"
DaemonSets = "daemonsets"