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:

    1. // $ cat myroute.cue
    2. "my-plc": {
    3. annotations: {}
    4. attributes: {}
    5. description: "My ingress route policy."
    6. labels: {}
    7. type: "policy"
    8. }
    9. template: {
    10. }

    Below is an example that we create a traffic split service mesh object in policy.

    1. "my-plc": {
    2. description: "My service mesh policy."
    3. type: "policy"
    4. }
    5. template: {
    6. #ServerWeight: {
    7. weight: int
    8. }
    9. parameter: {
    10. weights: [...#ServerWeight]
    11. }
    12. output: {
    13. apiVersion: "split.smi-spec.io/v1alpha3"
    14. kind: "TrafficSplit"
    15. metadata: name: context.name
    16. spec: {
    17. service: context.name
    18. backends: parameter.weights
    19. }
    20. }
    21. }

    Apply to our control plane to make this trait work:

    Then our end users can discover it immediately and use it in Application.

    1. cat <<EOF | vela up -f -
    2. apiVersion: core.oam.dev/v1beta1
    3. metadata:
    4. spec:
    5. components:
    6. - name: server-v1
    7. type: webservice
    8. properties:
    9. image: oamdev/hello-world:v1
    10. - name: server-v2
    11. type: webservice
    12. properties:
    13. image: oamdev/hello-world:v2
    14. policies:
    15. - type: my-plc
    16. name: unified
    17. properties:
    18. weights:
    19. - service: server-v1
    20. weight: 80
    21. - service: server-v2
    22. EOF

    The policy will generate Kubernetes resources by KubeVela like below:

    You can define any Kubernetes API objects in policies if you want.

    Special Policy

    Not all policies generate resources, there’re several built-in policies which are used to control the whole delivery precess and workflows.

    These special polices are usually coded in the application controller.