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:
Himanshu Singh
2026-07-14 16:19:53 +01:00
committed by GitHub
co-authored by hisingh
parent ca9152164f
commit 8bb75684c5
3 changed files with 26 additions and 4 deletions
+2 -1
View File
@@ -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) {
+17
View File
@@ -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)
}