Files
kubevela/pkg
544fc6042e Fix: defkit health conditions erroring when status is absent (#7299)
* Fix: defkit health conditions erroring when status is absent

Motivation:
defkit.ConditionExpr (used by HealthPolicyExpr/AllTrue) builds a CUE
comprehension over context.output.status.conditions. When status or
status.conditions doesn't exist yet - e.g. during the first few reconciles
after a Crossplane claim is created - that comprehension source is CUE
bottom (_|_). CUE's && does not short-circuit, so the bottom propagates
through the whole isHealth expression even past Exists() guards meant to
protect it. A condition entry without a type field hit the same problem.
Separately, ToCUE() indexed the filtered list at [0], which also errors on
an empty list regardless of a preceding len(...) > 0 check, for the same
non-short-circuit reason.

Approach:
- Preamble() now sources the comprehension from
  *context.output.status.conditions | []. CUE disjunctions discard any
  operand that evaluates to bottom, so this falls back to an empty list
  instead of erroring when status/conditions are absent, while still
  ranging over the real list when it exists. `if c.type != _|_` skips
  condition entries missing a type field instead of letting the
  comparison go bottom.
- ToCUE() now checks status/reason by filtering the condition list with
  len([for c in ... if ...]) > 0 instead of indexing [0], so there's
  never an out-of-range index to evaluate.

Testing:
Added TestConditionExprHandlesMissingStatus in
pkg/definition/defkit/health_expr_test.go, which builds a policy with
h.And(h.Exists("status"), h.Exists("status.conditions"),
h.AllTrue("Ready","Synced")) and runs it through health.CheckHealth
against five fixtures: no status, empty status, Ready+Synced true, Ready
false, and a condition entry missing type.

```release-note
Fixed `defkit` health policies built with `ConditionExpr`/`AllTrue` erroring
instead of evaluating to unhealthy when the target resource has no `status` or
`status.conditions` yet.
```

Report: https://github.com/kubevela/kubevela/issues/7284
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>

* Fix: guard c.status/c.reason against bottom in defkit condition ToCUE

A condition entry with a matching type but no status field (e.g. a
transient/partial condition) made the CUE comparison c.status == "..."
evaluate to bottom instead of false, causing a hard evaluation error
rather than an unhealthy verdict. Guard c.status and c.reason with
!= _|_ before comparing, mirroring the existing c.type guard in
Preamble().

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>

---------

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Co-authored-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
2026-08-12 11:31:23 +01:00
..
2026-03-18 21:11:22 -07:00