-
Notifications
You must be signed in to change notification settings - Fork 279
/
resources.go
93 lines (73 loc) · 1.63 KB
/
resources.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package types
import "time"
type Deployment struct {
Namespace string
Name string
Container string
}
type Machine struct {
Metadata MachineMetadata `json:"metadata"`
Status MachineStatus `json:"status"`
}
func (m *Machine) HasAnyLabel(labels []string) bool {
for _, label := range labels {
if _, ok := m.Metadata.Labels[label]; ok {
return true
}
}
return false
}
type MachineStatus struct {
NodeRef *ResourceRef `json:"nodeRef,omitempty"`
Conditions Conditions
}
type MachineMetadata struct {
Name string `json:"name,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
type ResourceRef struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Name string `json:"Name"`
}
type Conditions []Condition
type ConditionType string
type ConditionStatus string
type Condition struct {
Type ConditionType `json:"type"`
Status ConditionStatus `json:"status"`
}
type CAPICluster struct {
Metadata Metadata
Status ClusterStatus
}
type ClusterStatus struct {
Phase string
Conditions Conditions
}
type Metadata struct {
Name string
}
type Datastores struct {
Info Info `json:"Info"`
}
type Info struct {
FreeSpace float64 `json:"FreeSpace"`
}
type NowFunc func() time.Time
type NodeReadyChecker func(status MachineStatus) bool
func WithNodeRef() NodeReadyChecker {
return func(status MachineStatus) bool {
return status.NodeRef != nil
}
}
func WithNodeHealthy() NodeReadyChecker {
return func(status MachineStatus) bool {
for _, c := range status.Conditions {
if c.Type == "NodeHealthy" {
return c.Status == "True"
}
}
return false
}
}