upgrade

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheEntryTTL = 1 * time.Hour

CacheEntryTTL is how long an unaccessed entry lives before being swept.

View Source
var CompatibilityCacheSize = 2000

CompatibilityCacheSize is the maximum number of cache entries. Default 2000. Overridden at startup via --cue-compatibility-cache-size.

View Source
var EnableCUEVersionCompatibility = true

EnableCUEVersionCompatibility controls whether EnsureCueVersionCompatibility is applied at render time. Defaults to true. Can be disabled via --enable-cue-version-compatibility=false.

View Source
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 }
}
View Source
var OnCacheEviction func(reason string)

OnCacheEviction is called by the LRU cache when an entry is evicted. reason is "capacity" or "ttl".

View Source
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)

View Source
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

func InitCompatibilityCache(ctx context.Context, size int)

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

func RequiresUpgrade(cueStr string, targetVersion ...Version) (bool, []string, error)

RequiresUpgrade checks if the CUE string requires upgrading to the target version. If no targetVersion is provided, uses the version from GetCurrentVersion.

func Upgrade

func Upgrade(cueStr string, targetVersion ...Version) (string, error)

Upgrade applies all registered upgrades that apply to the given 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

type Version struct {
	Major int
	Minor int
}

Version identifies a release version for upgrade ordering.

func GetSupportedVersions

func GetSupportedVersions() []Version

GetSupportedVersions returns all registered KubeVela versions in ascending order.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a "Major.Minor" string (with optional leading "v") into a Version.

func (Version) Less

func (v Version) Less(other Version) bool

Less reports whether v is strictly earlier than other.

func (Version) String

func (v Version) String() string

String returns the canonical "Major.Minor" representation, e.g. "1.11".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL