mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-17 23:07:34 +00:00
Implements the data structures, functions, and API for per-output-type
policy caching with cascade invalidation. Note: Full integration into
the policy execution flow will be done in Part 5.
## What's Implemented
### 1. PolicyConfig with refresh fields (policy_transforms.go:782-809)
- RefreshMode type: RefreshAlways, RefreshNever, RefreshPeriodic
- OutputRefreshConfig struct: Mode, Interval, ForceRefresh
- PolicyConfig with nested Refresh for Spec, Labels, Annotations, Ctx
- Each output type has independent refresh control
### 2. extractRefreshConfig function (policy_transforms.go:845-882)
- Extracts config.refresh from CUE templates
- Applies defaults (all modes default to "never")
- Validates periodic mode requires interval > 0
### 3. Per-output-type cache storage (policy_transforms.go:932-954)
- CachedOutputData: per-type cache with metadata
- PolicyCacheRecord: new ConfigMap format with cascade tracking
- Helper functions: createPolicyCacheRecord, reconstructPolicyOutputFromCache, shouldRefreshOutput
### 4. Cascade ID computation (policy_transforms.go:1506-1525)
- computeCascadeID(): hashes upstream policy outputs
- Enables cascade invalidation when upstream policies refresh
### 5. New cache load function (policy_transforms.go:1593-1683)
- loadCachedPolicyRecord(): loads with cascade & refresh checks
- Checks Application hash, cascade ID, per-output-type refresh
- Old loadCachedPolicyFromConfigMap() kept for backwards compatibility
### 6. Removed CacheTTLSeconds from CRD
- Removed from PolicyDefinitionSpec (policy_definition.go)
- TTL now controlled via config.refresh in templates
- Removed deprecated test
### 7. CUE schema (vela-templates/definitions/internal/policy/app-policy-schema.cue)
- Defines #ApplicationPolicyTemplate with full API
- Provides type safety, validation, defaults
- Documents complete config.refresh API
## API Example
```cue
config: {
enabled: true
refresh: {
labels: { mode: "always" }
ctx: { mode: "periodic", interval: 300 }
}
}
```
## Status
✅ Infrastructure complete
✅ 162 tests passing
⏳ Full integration into execution flow: Part 5
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>