Documentation
¶
Index ¶
- Variables
- func EnsureCueVersionCompatibility(cueStr, defName string, defKind DefinitionKind, area TemplateArea) (string, bool)
- func InitCompatibilityCache(ctx context.Context, size int)
- func RegisterUpgrade(u upgradeEntry)
- func RequiresUpgrade(cueStr string, targetVersion ...Version) (bool, []string, error)
- func Upgrade(cueStr string, targetVersion ...Version) (string, error)
- type CUEUpgradeFunc
- type DefinitionKind
- type KubeVelaUpgradeFunc
- type TemplateArea
- type UpgradeFunc
- type Version
Constants ¶
This section is empty.
Variables ¶
var CacheEntryTTL = 1 * time.Hour
CacheEntryTTL is how long an unaccessed entry lives before being swept.
var CompatibilityCacheSize = 2000
CompatibilityCacheSize is the maximum number of cache entries. Default 2000. Overridden at startup via --cue-compatibility-cache-size.
var EnableCUEVersionCompatibility = true
EnableCUEVersionCompatibility controls whether EnsureCueVersionCompatibility is applied at render time. Defaults to true. Can be disabled via --enable-cue-version-compatibility=false.
var GetCurrentVersion func() string
GetCurrentVersion is a pluggable version provider. Consuming repos must set this at init time to return their own running version string (e.g. "v1.11.2"). If unset, all registered upgrades are applied (equivalent to "run everything").
Example (in kubevela's main package):
func init() {
upgrade.GetCurrentVersion = func() string { return version.VelaVersion }
}
var OnCacheEviction func(reason string)
OnCacheEviction is called by the LRU cache when an entry is evicted. reason is "capacity" or "ttl".
var OnRewrite func(fixID, fixVersion string, defKind DefinitionKind, area TemplateArea)
OnRewrite is called by EnsureCueVersionCompatibility after a successful cache-miss upgrade. Consuming repos set this to record metrics (counter increments per applied fix). Signature: (fixID, fixVersion, defKind, area string)
var OnUpgradeDuration func(defKind DefinitionKind, elapsed time.Duration)
OnUpgradeDuration is called by EnsureCueVersionCompatibility after the upgrade path runs. Consuming repos set this to record latency metrics. Signature: (defKind string, elapsed time.Duration)
Functions ¶
func EnsureCueVersionCompatibility ¶
func EnsureCueVersionCompatibility(cueStr, defName string, defKind DefinitionKind, area TemplateArea) (string, bool)
EnsureCueVersionCompatibility applies all upgrades for the current version to the provided CUE string, ensuring backward compatibility with legacy CUE syntax. Returns the upgraded template and whether any semantic upgrades were applied.
func InitCompatibilityCache ¶
InitCompatibilityCache reinitialises the cache with the given size and starts background TTL eviction. Safe to call multiple times (e.g. in tests): the previous eviction goroutine is stopped first.
func RegisterUpgrade ¶
func RegisterUpgrade(u upgradeEntry)
RegisterUpgrade registers an upgrade entry.
func RequiresUpgrade ¶
RequiresUpgrade checks if the CUE string requires upgrading to the target version. If no targetVersion is provided, uses the version from GetCurrentVersion.
Types ¶
type CUEUpgradeFunc ¶
type CUEUpgradeFunc struct {
ID string
CUEVersion Version
AssociatedVelaVersion Version
Reason string
Precheck func(cueStr string) bool
Upgrade func(cueStr string, file *cueast.File) (string, error)
}
CUEUpgradeFunc is a CUE compatibility fix triggered by the CUE language version. It applies when the running CUE language version (cue.LanguageVersion()) is >= CUEVersion, regardless of the KubeVela version. AssociatedVelaVersion is used only for registry ordering.
type DefinitionKind ¶
type DefinitionKind string
DefinitionKind identifies the type of definition for metrics, logs, and compatibility reports. It is an open string type — each consuming repo declares its own constants. Values should match the definition's Kind string for consistency, e.g. "Component", "Trait".
type KubeVelaUpgradeFunc ¶
type KubeVelaUpgradeFunc struct {
ID string
VelaVersion Version
Reason string
Precheck func(cueStr string) bool
Upgrade func(cueStr string, file *cueast.File) (string, error)
}
KubeVelaUpgradeFunc is a CUE compatibility fix triggered by a KubeVela version. It applies when the running (or target) KubeVela version is >= VelaVersion. Register with RegisterUpgrade.
type TemplateArea ¶
type TemplateArea string
TemplateArea identifies which part of a definition's CUE template a rewrite was applied to. It is an open string type — each consuming repo declares its own constants.
type UpgradeFunc ¶
type UpgradeFunc = KubeVelaUpgradeFunc
UpgradeFunc is a type alias for KubeVelaUpgradeFunc, preserved for backward compatibility.
type Version ¶
Version identifies a release version for upgrade ordering.
func GetSupportedVersions ¶
func GetSupportedVersions() []Version
GetSupportedVersions returns all registered KubeVela versions in ascending order.
func ParseVersion ¶
ParseVersion parses a "Major.Minor" string (with optional leading "v") into a Version.