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