Definition Version Control
Introduction
KubeVela supports Semantic Versioning for all types of Definitions, providing control over which versions of Definitions are used in Applications. This feature enables to specify exact version or version range for Definitions, enforce Semantic Versioning, and manage automatic upgrades of Definitions within KubeVela Applications.
Feature Overview
- Semantic Versioning for Definition
Definition versions are defined using Semantic Versioning, which follows the format MAJOR.MINOR.PATCH. This ensures control over how components evolve.
- Auto-Upgrade Control
KubeVela allows control over whether Applications automatically upgrade to newer Definition versions when they are available. The app.oam.dev/autoUpdate annotation is used to enable or disable auto-upgrade behavior.
- Auto-update enabled: The application automatically uses the latest compatible version of a Definition.
- Auto-update disabled: The application sticks to the specified version even if a new version of the Definition is released.
- Version Range Control
You can specify either an exact version or a version range for Definition in your application. If a version range is used, KubeVela will select the latest version that fits within the range.
Version ranges (@v1, @v1.2) only work when the Application sets app.oam.dev/autoUpdate: "true". Without it, KubeVela looks for a revision with exactly that name, so give the full version, such as configmap-component@v1.2.5.
User Guide
This publishes configmap-component at three versions and shows which one an Application with autoUpdate renders. Each version writes its own number into the ConfigMap, so you can read it back.
-
Create the namespace the Application runs in:
kubectl create namespace test -
Save this as
configmap-component-1.2.5.yamland apply it withkubectl apply -f configmap-component-1.2.5.yaml:apiVersion: core.oam.dev/v1beta1kind: ComponentDefinitionmetadata:name: configmap-componentnamespace: vela-systemspec:version: 1.2.5workload:definition:apiVersion: v1kind: ConfigMapschematic:cue:template: |output: {apiVersion: "v1"kind: "ConfigMap"metadata: name: context.namedata: version: "1.2.5"} -
Publish version
2.5.0, the breaking release. Apply the same file withversion: 2.5.0anddata: version: "2.5.0":apiVersion: core.oam.dev/v1beta1kind: ComponentDefinitionmetadata:name: configmap-componentnamespace: vela-systemspec:version: 2.5.0workload:definition:apiVersion: v1kind: ConfigMapschematic:cue:template: |output: {apiVersion: "v1"kind: "ConfigMap"metadata: name: context.namedata: version: "2.5.0"} -
List the revisions:
kubectl get definitionrevision -n vela-system | grep configmap-componentconfigmap-component-v1.2.5 1 1a4f3ac77e4fcfef Componentconfigmap-component-v2.5.0 2 e61e9b5e55b01c2b Component -
Deploy an Application that follows the
v1range:apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: test-appnamespace: testannotations:app.oam.dev/autoUpdate: "true"spec:components:- name: comptesttype: configmap-component@v1It renders
1.2.5, the highest version inv1.2.5.0is outside the range:kubectl get cm comptest -n test -o jsonpath='{.data.version}'1.2.5 -
Publish
1.2.7, a fix inside thev1range. Apply the same definition again withversion: 1.2.7anddata: version: "1.2.7".The Application moves to
1.2.7on its next resync, up to 5 minutes later, or as soon as you change it. Then:kubectl get cm comptest -n test -o jsonpath='{.data.version}'1.2.7 -
List the revisions again:
kubectl get definitionrevision -n vela-system | grep configmap-componentconfigmap-component-v1.2.5 1 1a4f3ac77e4fcfef Componentconfigmap-component-v1.2.7 3 86d7fb1a36566dea Componentconfigmap-component-v2.5.0 2 e61e9b5e55b01c2b Component
To clean up, run kubectl delete application test-app -n test and kubectl delete componentdefinition configmap-component -n vela-system.
Adding a version Field in CUE-based Definitions
In a CUE definition, put version under attributes. Leave it out if you don't need semantic versions, and revisions are numbered instead.
"configmap-component": {
type: "component"
attributes: {
workload: definition: {
apiVersion: "v1"
kind: "ConfigMap"
}
version: "1.2.5"
}
}
template: {
output: {
apiVersion: "v1"
kind: "ConfigMap"
metadata: name: parameter.name
data: version: "1.2.5"
}
parameter: {
// +usage=Name of the ConfigMap.
name: string
}
}