mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 12:06:38 +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
@@ -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