Application-Scoped Policies
Application-scoped policies allow platform engineers to apply organisational standards to Applications deployed in a namespace or across the entire cluster. Use them to enforce consistent labelling, inject configuration, apply security standards, or adapt Applications to their environment.
Policies come in two forms: global policies apply automatically to every Application without any developer involvement, and explicit policies are declared by developers in their Application's spec.policies.
Application-scoped policies are an alpha feature and are subject to change in future releases. The API, CUE template structure, and CLI commands may evolve based on feedback.
This feature is disabled by default. Enable it via feature gates when installing or upgrading KubeVela:
Helm:
helm install kubevela kubevela/vela-core \
--set "featureGates.enableApplicationScopedPolicies=true" \
--set "featureGates.enableGlobalPolicies=true"
Controller flags (if managing the controller directly):
--feature-gates=EnableApplicationScopedPolicies=true
--feature-gates=EnableGlobalPolicies=true
EnableGlobalPolicies is only required if you want to use global policies. EnableApplicationScopedPolicies is required for all application-scoped policy functionality.
If you encounter any issues, please report them on GitHub.
Make sure you've learned the basic knowledge about Definition Concept and how to manage definitions before continuing.
How It Works
When KubeVela reconciles an Application, application-scoped policies run as a pre-flight step before the Application is revisioned and deployed. Each policy renders a CUE template and applies its output to the Application specification before it is processed.
Global policies always run before explicit policies. Global policies execute in ascending priority order (lower value first), with alphabetical name as the tiebreaker for determinism. Explicit policies run after all global policies have completed, in the order they are declared in spec.policies.
Creating an Application-Scoped PolicyDefinition
Use vela def init to scaffold a new policy definition:
vela def init add-team-labels -t policy --desc "Add team and environment labels to every Application." > add-team-labels.cue
The scaffold will look like:
"add-team-labels": {
annotations: {}
attributes: {}
description: "Add team and environment labels to every Application."
labels: {}
type: "policy"
}
template: {
}
Set attributes.scope to "Application" and fill in the template:
"add-team-labels": {
attributes: {
scope: "Application"
}
description: "Add team and environment labels to every Application."
type: "policy"
}
template: {
parameter: {
team: string
environment: *"production" | string
}
config: {
enabled: true
}
output: {
labels: {
"platform.io/team": parameter.team
"platform.io/environment": parameter.environment
}
}
}
Apply it to the cluster:
vela def apply add-team-labels.cue
Use it in an Application:
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: my-app
namespace: default
spec:
components:
- name: frontend
type: webservice
properties:
image: nginx:latest
policies:
- name: team-labels
type: add-team-labels
properties:
team: platform-team
environment: production
Before reconciliation continues, the Application will have platform.io/team: platform-team and platform.io/environment: production merged into its metadata labels.