support node status filter
This commit is contained in:
@@ -37,6 +37,36 @@ func (*nodeSearcher) get(namespace, name string) (interface{}, error) {
|
|||||||
return informers.SharedInformerFactory().Core().V1().Nodes().Lister().Get(name)
|
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
|
// exactly Match
|
||||||
func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool {
|
func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool {
|
||||||
for k, v := range match {
|
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 {
|
if _, ok := item.Labels[labelKey]; !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
case Status:
|
||||||
|
if getNodeStatus(item) != v {
|
||||||
|
return false
|
||||||
|
}
|
||||||
case Keyword:
|
case Keyword:
|
||||||
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
|
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ const (
|
|||||||
StatusBound = "bound"
|
StatusBound = "bound"
|
||||||
StatusLost = "lost"
|
StatusLost = "lost"
|
||||||
StatusComplete = "complete"
|
StatusComplete = "complete"
|
||||||
|
StatusWarning = "warning"
|
||||||
|
StatusUnschedulable = "unschedulable"
|
||||||
app = "app"
|
app = "app"
|
||||||
Deployments = "deployments"
|
Deployments = "deployments"
|
||||||
DaemonSets = "daemonsets"
|
DaemonSets = "daemonsets"
|
||||||
|
|||||||
Reference in New Issue
Block a user