Files
kubevela/pkg/features
lif e65938087d Feat: Validate undeclared parameters in application definitions (#7075)
* Feat: Validate undeclared parameters in application definitions (#6862)

Add a new feature gate ValidateUndeclaredParameters that rejects
parameters not declared in the CUE definition schema at admission time.
When enabled, any parameter field not present in the template's parameter
stanza will cause a validation error.

Signed-off-by: majiayu000 <1835304752@qq.com>

* Fix: Handle CUE pattern constraints and improve undeclared param validation

- Detect pattern constraints ([string]: T) using LookupPath to avoid
  false positives on webservice labels/annotations fields
- Use GetSelectorLabel() for safe selector extraction
- Add klog debug logging when schema compilation fails
- Sort undeclared field names for deterministic error messages
- Add test cases for pattern constraints and sorted output

Signed-off-by: majiayu000 <1835304752@qq.com>

* Fix: go fmt alignment in validate_test.go

Signed-off-by: majiayu000 <1835304752@qq.com>

* fix: address review feedback on PR #7075

- Handle conditional parameter declarations via two-pass schema
  compilation: first without params for base fields, then with
  declared params to resolve CUE conditionals
- Return nil from findUndeclaredFields when schema.Fields() errors
  to prevent false positives from empty declared map
- Recurse into list elements containing structs using cue.AnyIndex
  so undeclared fields inside arrays are detected
- Save/restore previous feature gate state in tests instead of
  resetting to fixed values

Signed-off-by: majiayu000 <1835304752@qq.com>

---------

Signed-off-by: majiayu000 <1835304752@qq.com>
2026-03-22 12:45:02 -07:00
..