A collection of KubeVela X-Definitions written in Go using the defkit fluent builder API.
This module contains Go-based KubeVela X-Definitions that can be applied to any KubeVela cluster. Definitions are written in Go and generate CUE automatically via the defkit framework.
- components/ - ComponentDefinitions for workload types
- traits/ - TraitDefinitions for operational behaviors
- policies/ - PolicyDefinitions for application policies
- workflowsteps/ - WorkflowStepDefinitions for delivery workflows
- cmd/defkit/ - CLI tool for generating CUE and exporting definitions
- cmd/register/ - Registry entry point used by
vela def apply-module(fast path) - vela-templates/definitions/ - Generated CUE output (do not edit manually)
- test/ - E2E test suite and test data
vela def apply-module github.com/oam-dev/vela-go-definitionsvela def list-module github.com/oam-dev/vela-go-definitionsvela def validate-module github.com/oam-dev/vela-go-definitionsvela def apply-module github.com/oam-dev/vela-go-definitions --namespace my-namespacevela def apply-module github.com/oam-dev/vela-go-definitions --dry-run- Go 1.23+
- golangci-lint (installed automatically by
make lintif missing)
Before submitting a pull request, run make reviewable to ensure your changes are ready for review. This is the same pattern used in the kubevela repository.
make reviewableThis runs the following checks in order:
- generate - Regenerates CUE definitions from Go into
vela-templates/definitions/ - fmt - Formats all Go code
- vet - Runs
go veton all packages - lint - Runs
golangci-lint - check-diff - Verifies no uncommitted changes in generated files
If check-diff fails, it means the generated CUE files are out of date. Run make generate and commit the updated files.
make generate # Regenerate CUE definitions
make fmt # Format Go code
make vet # Vet Go code
make lint # Lint Go code
make check-diff # Verify generated files are up-to-date
make tidy # Tidy go.mod dependenciesThere are two entry points under cmd/:
cmd/defkit — the main CLI (cobra-based) for local development:
# Generate CUE files into vela-templates/definitions/
go run ./cmd/defkit generate
# Export all registered definitions as JSON
go run ./cmd/defkit registercmd/register — a minimal entry point that outputs all definitions as JSON. This is the conventional path that vela def apply-module uses to discover definitions via the fast registry pattern. It must exist at this exact path (cmd/register/main.go) for apply-module to use the optimized loading strategy instead of falling back to slower AST-based discovery.
# Used internally by: vela def apply-module .
go run ./cmd/register- Create a new Go file in the appropriate directory
- Add an
init()function that registers your definition - Use the defkit package fluent API to define your component/trait/policy/workflow-step
- Run
make reviewableto regenerate CUE and validate
Example component definition:
package components
import "github.com/oam-dev/kubevela/pkg/definition/defkit"
func init() {
defkit.Register(MyComponent())
}
func MyComponent() *defkit.ComponentDefinition {
image := defkit.String("image").Mandatory().Description("Container image")
replicas := defkit.Int("replicas").Default(1).Description("Number of replicas")
return defkit.NewComponent("my-component").
Description("My custom component").
Workload("apps/v1", "Deployment").
Params(image, replicas).
Template(myComponentTemplate)
}
func myComponentTemplate(tpl *defkit.Template) {
vela := defkit.VelaCtx()
image := defkit.String("image")
replicas := defkit.Int("replicas")
deployment := defkit.NewResource("apps/v1", "Deployment").
Set("spec.replicas", replicas).
Set("spec.selector.matchLabels[app.oam.dev/component]", vela.Name()).
Set("spec.template.spec.containers[0].name", vela.Name()).
Set("spec.template.spec.containers[0].image", image)
tpl.Output(deployment)
}make test-unitE2E tests validate definitions against a live KubeVela cluster. Each test applies an Application YAML, waits for it to reach running status, then validates:
- Auto-derived checks (all 77 definitions): workflow steps succeeded, component resources exist with correct image
- Extra checks (via
.expect.yamlfiles): trait effects, policy side effects, workflow step outputs
# Set up a local k3d cluster with KubeVela and all defkit definitions installed
# Prerequisites: docker, k3d, kubectl, vela CLI
make e2e-setup
# Run tests by category
make test-e2e-components
make test-e2e-traits
make test-e2e-policies
make test-e2e-workflowsteps
# Run all E2E tests
make test-e2e
# Tear down the cluster when done
make e2e-teardowntest/builtin-definition-example/
applications/ # Application YAMLs (test inputs)
components/ # 8 component tests
trait/ # 29 trait tests
policies/ # 9 policy tests
workflowsteps/ # 31 workflow step tests
expectations/ # Extra validation (additive, optional)
trait/ # Trait-specific checks (env vars, labels, etc.)
policies/ # Policy-specific checks
workflowsteps/ # Workflow step output checks
| Variable | Default | Description |
|---|---|---|
PROCS |
10 | Number of parallel test processes |
E2E_TIMEOUT |
10m | Test timeout duration |
TESTDATA_PATH |
test/builtin-definition-example |
Path to test data |
DEFINITIONS_DIR |
vela-templates/definitions |
Output directory for generated CUE |
E2E_CLUSTER |
e2e-test |
k3d cluster name for local testing |
GitHub Actions workflows automatically run on push and pull requests to main:
- Unit Tests - Runs all unit tests
- Reviewable - Runs
make generate,make fmt,make vet, linting, andcheck-diffto ensure generated files are up-to-date - E2E Tests - Runs component, trait, policy, and workflow step e2e tests in parallel jobs against a k3d cluster with defkit definitions installed
Apache License 2.0