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
94
95
package scale
type OperatorKind struct {
Group string
Kind string
ReadyCondition string
InCluster bool
}
type Operators []OperatorKind
var OurOperators = Operators{}
type CustomResourceCondition struct {
Type string
Status string
ObservedGeneration int64
}
type CustomResource struct {
Group string
Kind string
Namespace string
Name string
Generation int64
ObservedGeneration int64
Deleting bool
Finalizers int
Conditions []CustomResourceCondition
}
func (r Operators) InCluster() Operators {
var out Operators
for _, k := range r {
if k.InCluster {
out = append(out, k)
}
}
return out
}
func (r Operators) lookup(group, kind string) (OperatorKind, bool) {
for _, k := range r {
if k.Group == group && k.Kind == kind {
return k, true
}
}
return OperatorKind{}, false
}
func (r Operators) Unreconciled(crs []CustomResource) []CustomResource {
var out []CustomResource
for _, cr := range crs {
k, ok := r.lookup(cr.Group, cr.Kind)
if !ok || !k.InCluster {
continue
}
if !k.Reconciled(cr) {
out = append(out, cr)
}
}
return out
}
func (k OperatorKind) Reconciled(cr CustomResource) bool {
if cr.Deleting {
return cr.Finalizers == 0
}
if cr.ObservedGeneration != 0 && cr.ObservedGeneration < cr.Generation {
return false
}
for _, c := range cr.Conditions {
if c.Type != k.ReadyCondition {
continue
}
if c.ObservedGeneration != 0 && c.ObservedGeneration < cr.Generation {
return false
}
return c.Status == "True"
}
return false
}