@@ -22,70 +22,86 @@ import (
22
22
"k8s.io/klog/v2"
23
23
)
24
24
25
+ type ObjectStatus struct {
26
+ GVK schema.GroupVersionKind
27
+ NameNamespace types.NamespacedName
28
+ IsHealthy bool
29
+ Status string
30
+ Message string
31
+ }
32
+
25
33
// ApplyResults contains the results of an Apply operation.
26
34
type ApplyResults struct {
27
- total int
28
- applySuccessCount int
29
- applyFailCount int
30
- pruneSuccessCount int
31
- pruneFailCount int
32
- healthyCount int
33
- unhealthyCount int
35
+ Total int
36
+ ApplySuccessCount int
37
+ ApplyFailCount int
38
+ PruneSuccessCount int
39
+ PruneFailCount int
40
+ HealthyCount int
41
+ UnhealthyCount int
42
+ Objects []ObjectStatus
34
43
}
35
44
36
45
// AllApplied is true if the desired state has been successfully applied for all objects.
37
46
// Note: you likely also want to check AllHealthy, if you want to be sure the objects are "ready".
38
47
func (r * ApplyResults ) AllApplied () bool {
39
48
r .checkInvariants ()
40
49
41
- return r .applyFailCount == 0 && r .pruneFailCount == 0
50
+ return r .ApplyFailCount == 0 && r .PruneFailCount == 0
42
51
}
43
52
44
53
// AllHealthy is true if all the objects have been applied and have converged to a "ready" state.
45
54
// Note that this is only meaningful if AllApplied is true.
46
55
func (r * ApplyResults ) AllHealthy () bool {
47
56
r .checkInvariants ()
48
57
49
- return r .unhealthyCount == 0
58
+ return r .UnhealthyCount == 0
50
59
}
51
60
52
61
// checkInvariants is an internal function that warns if the object doesn't match the expected invariants.
53
62
func (r * ApplyResults ) checkInvariants () {
54
- if r .total != (r .applySuccessCount + r .applyFailCount ) {
63
+ if r .Total != (r .ApplySuccessCount + r .ApplyFailCount ) {
55
64
klog .Warningf ("consistency error (apply counts): %#v" , r )
56
- } else if r .total != (r .healthyCount + r .unhealthyCount ) {
65
+ } else if r .Total != (r .HealthyCount + r .UnhealthyCount ) {
57
66
// This "invariant" only holds when all objects could be applied
58
67
klog .Warningf ("consistency error (healthy counts): %#v" , r )
59
68
}
60
69
}
61
70
62
71
// applyError records that the apply of an object failed with an error.
63
72
func (r * ApplyResults ) applyError (gvk schema.GroupVersionKind , nn types.NamespacedName , err error ) {
64
- r .applyFailCount ++
73
+ r .ApplyFailCount ++
65
74
klog .Warningf ("error from apply on %s %s: %v" , gvk , nn , err )
66
75
}
67
76
68
77
// applySuccess records that an object was applied and this succeeded.
69
78
func (r * ApplyResults ) applySuccess (gvk schema.GroupVersionKind , nn types.NamespacedName ) {
70
- r .applySuccessCount ++
79
+ r .ApplySuccessCount ++
71
80
}
72
81
73
82
// pruneError records that the prune of an object failed with an error.
74
83
func (r * ApplyResults ) pruneError (gvk schema.GroupVersionKind , nn types.NamespacedName , err error ) {
75
- r .pruneFailCount ++
84
+ r .PruneFailCount ++
76
85
klog .Warningf ("error from pruning on %s %s: %v" , gvk , nn , err )
77
86
}
78
87
79
88
// pruneSuccess records that an object was pruned and this succeeded.
80
89
func (r * ApplyResults ) pruneSuccess (gvk schema.GroupVersionKind , nn types.NamespacedName ) {
81
- r .pruneSuccessCount ++
90
+ r .PruneSuccessCount ++
82
91
}
83
92
84
93
// reportHealth records the health of an object.
85
- func (r * ApplyResults ) reportHealth (gvk schema.GroupVersionKind , nn types.NamespacedName , isHealthy bool ) {
94
+ func (r * ApplyResults ) reportHealth (gvk schema.GroupVersionKind , nn types.NamespacedName , isHealthy bool , status , message string ) {
95
+ r .Objects = append (r .Objects , ObjectStatus {
96
+ GVK : gvk ,
97
+ NameNamespace : nn ,
98
+ IsHealthy : isHealthy ,
99
+ Message : message ,
100
+ Status : status ,
101
+ })
86
102
if isHealthy {
87
- r .healthyCount ++
103
+ r .HealthyCount ++
88
104
} else {
89
- r .unhealthyCount ++
105
+ r .UnhealthyCount ++
90
106
}
91
107
}
0 commit comments