mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-18 15:27:45 +00:00
This commit completes the migration from the old transforms API to the
simpler output API, and fixes two critical bugs discovered during testing.
## Part 1: API Migration (transforms → output)
**Old API**:
```cue
transforms: {
spec: {type: "replace", value: {components: [...]}}
labels: {type: "merge", value: {"key": "val"}}
}
```
**New API**:
```cue
output: {
components: [...] // replaces spec.components (always replace)
workflow: {...} // replaces spec.workflow (always replace)
policies: [...] // replaces spec.policies (always replace)
labels: {"key": "val"} // always merge
annotations: {...} // always merge
ctx: {...} // runtime-only context
}
```
**Implementation** (policy_transforms.go):
- Added PolicyOutput struct for new API
- Added extractOutput() to parse output field
- Added applyPolicyTransform() to apply output to Application
- Updated renderPolicy() to support both APIs temporarily
- Reject old transforms API with clear error message
## Part 2: Bug Fixes
### Bug 1: Policy modifications lost during status update
**Problem**: `Status().Patch()` with `client.Merge` refreshes entire object
from API server, losing in-memory spec modifications made by policies.
**Symptom**: Workflows failed with "component not found" errors.
**Fix** (revision.go:544-555): Save/restore app.Spec around patchStatus().
### Bug 2: Infinite ApplicationRevision creation
**Problem**: RawExtension JSON had inconsistent byte representations,
causing DeepEqualRevision() failures and infinite revision creation.
**Symptom**: 100+ identical ApplicationRevisions created.
**Fix** (revision.go:136-146): Normalize component properties JSON in
gatherRevisionSpec() for consistent comparison.
## Testing
- Migrated policy_validation_test.go to output API (14 tests)
- Verified in test cluster: 1 revision per change, workflows work correctly
- Note: policy_transforms_test.go migration in progress
Tested with OCM policy creating ManifestWork - single revision created,
workflow finds correct components.