Policy Definition
Generate resources in policy is similar to trait, policy can be used to define things across components.
Let’s use to create a basic policy scaffold:
The content of the scaffold expected to be:
// $ cat myroute.cue
"my-plc": {
annotations: {}
attributes: {}
description: "My ingress route policy."
labels: {}
type: "policy"
}
template: {
}
The rule is aligned with component definition, you must specify output
, while you can use outputs
for more objects, the format as below:
"my-plc": {
description: "My service mesh policy."
type: "policy"
}
template: {
#ServerWeight: {
}
parameter: {
weights: [...#ServerWeight]
}
output: {
apiVersion: "split.smi-spec.io/v1alpha3"
kind: "TrafficSplit"
metadata: name: context.name
spec: {
service: context.name
backends: parameter.weights
}
}
}
Apply to our control plane to make this Policy work:
Then our end users can discover it immediately and use it in Application
.
After using vela up
by the following command:
cat <<EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
metadata:
spec:
components:
- name: server-v1
type: webservice
properties:
image: oamdev/hello-world:v1
- name: server-v2
type: webservice
properties:
image: oamdev/hello-world:v2
policies:
- type: my-plc
name: unified
properties:
weights:
- service: server-v1
weight: 80
- service: server-v2
The policy will generate Kubernetes resources by KubeVela like below:
Not all policies generate resources, there’re several built-in policies which are used to control the whole delivery precess and workflows.
tip
These special polices are usually coded in the application controller.