/
util.go
57 lines (47 loc) · 1.09 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package detective
import (
"net"
core "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog/v2"
)
func (d *Detective) NodeIsSchedulabeleAndRunning(node *core.Node) bool {
if node.Spec.Unschedulable {
return false
}
if len(node.Status.Conditions) == 0 {
return false
}
if !d.nodeFilter.MatchString(node.Name) {
return false
}
for _, cond := range node.Status.Conditions {
if cond.Type == core.NodeReady && cond.Status != core.ConditionTrue {
klog.V(3).Infof("Ignoring node %v with %v condition status %v", node.Name, cond.Type, cond.Status)
return false
}
}
return true
}
func (d *Detective) ListNodesWithPredicate(predicate func(node *v1.Node) bool) ([]*v1.Node, error) {
nodes, err := d.informers.Core().V1().Nodes().Lister().List(labels.Everything())
if err != nil {
return nil, err
}
var filtered []*v1.Node
for i := range nodes {
if predicate(nodes[i]) {
filtered = append(filtered, nodes[i])
}
}
return filtered, nil
}
func inc(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
}
}