/
instance_select.go
61 lines (46 loc) · 1.45 KB
/
instance_select.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
58
59
60
61
package collectors
import "time"
// Selector is a function type that defines if an instance should be selected.
type InstanceSelector func(i *Instance) bool
func HasEC2Data(i *Instance) bool { return i.HasEC2Data() }
func HasASGData(i *Instance) bool { return i.HasASGData() }
func HasNodeData(i *Instance) bool { return i.HasNodeData() }
func HasSpotData(i *Instance) bool { return i.Spot.InstanceID != "" }
// Deprecated: Should use filters instead.
func PendingLifecycleCompletion(i *Instance) bool { return i.PendingLifecycleCompletion() }
// Deprecated: Should use filters instead.
func HasLifecycleMessage(i *Instance) bool { return i.HasLifecycleMessage() }
func HasEC2State(states ...string) InstanceSelector {
return func(i *Instance) bool { return i.HasEC2State(states...) }
}
func LifecycleTriggeredOlderThan(age time.Duration) InstanceSelector {
return func(i *Instance) bool {
return time.Since(i.ASG.TriggeredAt) > age
}
}
func LifecycleDeleted(i *Instance) bool {
return i.ASG.Deleted
}
func LifecycleCompleted(i *Instance) bool {
return i.ASG.Completed
}
func HasTaint(key string) InstanceSelector {
return func(i *Instance) bool {
for _, taint := range i.Node.Taints {
if taint.Key == key {
return true
}
}
return false
}
}
func HasSpotStatusCode(codes ...string) InstanceSelector {
return func(i *Instance) bool {
for _, code := range codes {
if code == i.Spot.StatusCode {
return true
}
}
return false
}
}