mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 03:56:36 +00:00
propagate CUE health-eval errors from GetStatus (#7226)
Signed-off-by: hisingh <hisingh@guidewire.com> Co-authored-by: hisingh <hisingh@guidewire.com>
This commit is contained in:
co-authored by
hisingh
parent
ca9152164f
commit
8bb75684c5
@@ -27,6 +27,7 @@ import (
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/klog/v2"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
monitorContext "github.com/kubevela/pkg/monitor/context"
|
||||
@@ -262,12 +263,15 @@ func (h *AppHandler) collectTraitHealthStatus(comp *appfile.Component, tr *appfi
|
||||
return common.ApplicationTraitStatus{}, nil, errors.WithMessagef(err, "app=%s, comp=%s, trait=%s, evaluate status message error", appName, comp.Name, tr.Name)
|
||||
}
|
||||
statusResult, err := tr.EvalStatus(templateContext)
|
||||
if err == nil && statusResult != nil {
|
||||
if err != nil {
|
||||
klog.Warningf("app=%s, comp=%s, trait=%s, evaluate trait status error (best-effort): %v", appName, comp.Name, tr.Name, err)
|
||||
}
|
||||
if statusResult != nil {
|
||||
traitStatus.Healthy = statusResult.Healthy
|
||||
traitStatus.Message = statusResult.Message
|
||||
traitStatus.Details = statusResult.Details
|
||||
}
|
||||
return traitStatus, extractOutputs(templateContext), err
|
||||
return traitStatus, extractOutputs(templateContext), nil
|
||||
}
|
||||
|
||||
// collectWorkloadHealthStatus collect workload health status
|
||||
@@ -302,7 +306,7 @@ func (h *AppHandler) collectWorkloadHealthStatus(ctx context.Context, comp *appf
|
||||
}
|
||||
statusResult, err := comp.EvalStatus(templateContext)
|
||||
if err != nil {
|
||||
return false, nil, nil, errors.WithMessagef(err, "app=%s, comp=%s, evaluate workload status message error", appName, comp.Name)
|
||||
klog.Warningf("app=%s, comp=%s, evaluate workload status error (best-effort): %v", appName, comp.Name, err)
|
||||
}
|
||||
if statusResult != nil {
|
||||
status.Healthy = statusResult.Healthy
|
||||
|
||||
@@ -18,6 +18,7 @@ package health
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
goerrors "errors"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -104,7 +105,7 @@ func GetStatus(templateContext map[string]interface{}, request *StatusRequest) (
|
||||
Healthy: healthy,
|
||||
Message: message,
|
||||
Details: statusMap,
|
||||
}, nil
|
||||
}, goerrors.Join(mapErr, healthErr, msgErr)
|
||||
}
|
||||
|
||||
func getStatusMessage(templateContext map[string]interface{}, customStatusTemplate string, parameter interface{}) (string, error) {
|
||||
|
||||
@@ -1048,3 +1048,20 @@ required: string | *"default"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetStatus_PropagatesHealthEvalError is the regression test from issue #7141:
|
||||
// GetStatus must not silently discard a CUE health-policy evaluation error.
|
||||
func TestGetStatus_PropagatesHealthEvalError(t *testing.T) {
|
||||
templateContext := map[string]interface{}{
|
||||
"output": map[string]interface{}{
|
||||
"spec": map[string]interface{}{"replicas": int64(1)},
|
||||
"status": map[string]interface{}{"readyReplicas": int64(1)},
|
||||
},
|
||||
}
|
||||
brokenPolicy := `isHealth: context.output.spec.replicas + "not-a-number" > 0`
|
||||
|
||||
result, err := GetStatus(templateContext, &StatusRequest{Health: brokenPolicy})
|
||||
assert.Error(t, err, "GetStatus must surface the health policy evaluation error")
|
||||
assert.NotNil(t, result, "GetStatus should still return a best-effort result")
|
||||
assert.False(t, result.Healthy)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user