Skip to content

Commit ef0b581

Browse files
committed
Capture error as part of health computation and propagate it to health tracker. This will be returned to the caller as part of object result
1 parent 2a9fe22 commit ef0b581

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

applylib/applyset/applyset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
kubectlapply "sigs.k8s.io/kubebuilder-declarative-pattern/applylib/forked/github.com/kubernetes/kubectl/pkg/cmd/apply"
3737
)
3838

39-
type ComputeHealthCallback func(*unstructured.Unstructured) (bool, string)
39+
type ComputeHealthCallback func(*unstructured.Unstructured) (bool, string, error)
4040

4141
// ApplySet is a set of objects that we want to apply to the cluster.
4242
//
@@ -270,8 +270,8 @@ func (a *ApplySet) ApplyOnce(ctx context.Context) (*ApplyResults, error) {
270270
tracker.lastApplied = lastApplied
271271
results.applySuccess(gvk, nn)
272272
message := ""
273-
tracker.isHealthy, message = a.computeHealth(lastApplied)
274-
results.reportHealth(gvk, nn, tracker.isHealthy, message)
273+
tracker.isHealthy, message, err = a.computeHealth(lastApplied)
274+
results.reportHealth(gvk, nn, tracker.isHealthy, message, err)
275275
}
276276

277277
// We want to be more cautions on pruning and only do it if all manifests are applied.

applylib/applyset/health.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ import (
2525
)
2626

2727
// IsHealthy reports whether the object should be considered "healthy"
28-
func IsHealthy(u *unstructured.Unstructured) (bool, string) {
28+
func IsHealthy(u *unstructured.Unstructured) (bool, string, error) {
2929
result, err := status.Compute(u)
3030
if err != nil {
3131
klog.Infof("unable to compute condition for %s", humanName(u))
32-
return false, result.Message
32+
return false, result.Message, err
3333
}
3434
switch result.Status {
3535
case status.InProgressStatus:
36-
return false, result.Message
36+
return false, result.Message, nil
3737
case status.FailedStatus:
38-
return false, result.Message
38+
return false, result.Message, nil
3939
case status.TerminatingStatus:
40-
return false, result.Message
40+
return false, result.Message, nil
4141
case status.UnknownStatus:
4242
klog.Warningf("unknown status for %s", humanName(u))
43-
return false, result.Message
43+
return false, result.Message, nil
4444
case status.CurrentStatus:
45-
return true, result.Message
45+
return true, result.Message, nil
4646
default:
4747
klog.Warningf("unknown status value %s", result.Status)
48-
return false, result.Message
48+
return false, result.Message, nil
4949
}
5050
}
5151

applylib/applyset/results.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ func (r *ApplyResults) pruneSuccess(gvk schema.GroupVersionKind, nn types.Namesp
113113
}
114114

115115
// reportHealth records the health of an object.
116-
func (r *ApplyResults) reportHealth(gvk schema.GroupVersionKind, nn types.NamespacedName, isHealthy bool, message string) {
116+
func (r *ApplyResults) reportHealth(gvk schema.GroupVersionKind, nn types.NamespacedName, isHealthy bool, message string, err error) {
117117
r.Objects = append(r.Objects, ObjectStatus{
118118
GVK: gvk,
119119
NameNamespace: nn,
120120
IsHealthy: isHealthy,
121121
IsPruned: false,
122122
Message: message,
123+
Error: err,
123124
})
124125
if isHealthy {
125126
r.healthyCount++

0 commit comments

Comments
 (0)