Built-in Policy Type

    Allow configuration drift for applied resources, delivery the resource without continuously reconciliation.

    Examples (apply-once)

    It’s generally used in scenario.

    Specification (apply-once)

    rules (apply-once)

    NameDescriptionTypeRequiredDefault
    selectorSpecify how to select the targets of the rule.selectorfalse
    strategySpecify the strategy for configuring the resource level configuration drift behaviour.true
    selector (apply-once)
    NameDescriptionTypeRequiredDefault
    componentNamesSelect resources by component names.[]stringfalse
    componentTypesSelect resources by component types.[]stringfalse
    oamTypesSelect resources by oamTypes (COMPONENT or TRAIT).[]stringfalse
    traitTypesSelect resources by trait types.[]stringfalse
    resourceTypesSelect resources by resource types (like Deployment).[]stringfalse
    resourceNamesSelect resources by their names.[]stringfalse
    strategy (apply-once)
    NameDescriptionTypeRequiredDefault
    affectWhen the strategy takes effect,e.g. onUpdate、onStateKeep.stringfalse
    pathSpecify the path of the resource that allow configuration drift.[]stringtrue

    Garbage-Collect

    Description

    Configure the garbage collect behaviour for the application.

    Examples (garbage-collect)

    It’s used in scenario. It can be used to configure the collection policy, e.g. don’t delete the legacy resources when updating.

    1. kind: Application
    2. metadata:
    3. name: first-vela-app
    4. spec:
    5. components:
    6. - name: express-server
    7. type: webservice
    8. properties:
    9. image: oamdev/hello-world
    10. port: 8000
    11. traits:
    12. - type: ingress-1-20
    13. properties:
    14. domain: testsvc.example.com
    15. http:
    16. "/": 8000
    17. policies:
    18. - name: keep-legacy-resource
    19. type: garbage-collect
    20. properties:
    21. keepLegacyResource: true
    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: garbage-collect-app
    5. spec:
    6. components:
    7. - name: hello-world-new
    8. type: webservice
    9. properties:
    10. image: oamdev/hello-world
    11. traits:
    12. - type: expose
    13. properties:
    14. port: [8000]
    15. policies:
    16. - name: garbage-collect
    17. type: garbage-collect
    18. properties:
    19. rules:
    20. - selector:
    21. traitTypes:
    22. - expose
    23. strategy: onAppDelete

    Specification (garbage-collect)

    NameDescriptionTypeRequiredDefault
    keepLegacyResourceIf is set, outdated versioned resourcetracker will not be recycled automatically, outdated resources will be kept until resourcetracker be deleted manually.boolfalsefalse
    rulesSpecify the list of rules to control gc strategy at resource level, if one resource is controlled by multiple rules, first rule will be used.false

    rules (garbage-collect)

    selector (garbage-collect)
    NameDescriptionTypeRequiredDefault
    componentNamesSelect resources by component names.[]stringfalse
    componentTypesSelect resources by component types.[]stringfalse
    oamTypesSelect resources by oamTypes (COMPONENT or TRAIT).[]stringfalse
    traitTypesSelect resources by trait types.[]stringfalse
    resourceTypesSelect resources by resource types (like Deployment).[]stringfalse
    resourceNamesSelect resources by their names.[]stringfalse

    Description

    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: example-app-rollout
    5. namespace: default
    6. spec:
    7. components:
    8. - name: hello-world-server
    9. type: webservice
    10. properties:
    11. image: crccheck/hello-world
    12. ports:
    13. - port: 8000
    14. expose: true
    15. type: webservice
    16. policies:
    17. - name: health-policy-demo
    18. type: health
    19. properties:
    20. probeInterval: 5
    21. probeTimeout: 10

    Specification (health)

    NameDescriptionTypeRequiredDefault
    probeTimeoutSpecify health checking timeout(seconds), default 10s.intfalse10
    probeIntervalSpecify health checking interval(seconds), default 30s.intfalse30

    Override

    Description

    Describe the configuration to override when deploying resources, it only works with specified deploy step in workflow.

    Examples (override)

    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: advance-override
    5. namespace: examples
    6. spec:
    7. components:
    8. - name: nginx-advance-override-legacy
    9. type: webservice
    10. properties:
    11. image: nginx:1.20
    12. - name: nginx-advance-override-latest
    13. type: webservice
    14. properties:
    15. image: nginx
    16. policies:
    17. type: topology
    18. properties:
    19. clusterLabelSelector:
    20. region: hangzhou
    21. - name: topology-local
    22. type: topology
    23. properties:
    24. clusters: ["local"]
    25. namespace: examples-alternative
    26. - name: override-nginx-legacy
    27. type: override
    28. properties:
    29. selector: ["nginx-advance-override-legacy"]
    30. - name: override-nginx-latest
    31. type: override
    32. properties:
    33. selector: ["nginx-advance-override-latest", "nginx-advance-override-stable"]
    34. components:
    35. - name: nginx-advance-override-stable
    36. type: webservice
    37. properties:
    38. image: nginx:stable
    39. workflow:
    40. steps:
    41. - type: deploy
    42. name: deploy-local
    43. properties:
    44. policies: ["topology-local", "override-nginx-legacy"]
    45. name: deploy-hangzhou
    46. properties:
    47. policies: ["topology-hangzhou-clusters", "override-nginx-latest"]

    Specification (override)

    NameDescriptionTypeRequiredDefault
    componentsSpecify the overridden component configuration.[]componentstrue
    selectorSpecify a list of component names to use, if empty, all components will be selected.[]stringfalse

    components (override)

    NameDescriptionTypeRequiredDefault
    nameSpecify the name of the patch component, if empty, all components will be merged.stringfalse
    typeSpecify the type of the patch component.stringfalse
    propertiesSpecify the properties to override.map[string]_false
    traitsSpecify the traits to override.[]traitsfalse
    traits (override)

    Description

    Describe the configuration to replicate components when deploying resources, it only works with specified deploy step in workflow.

    Examples (replication)

    In KubeVela, we can dispatch resources across the clusters. But projects like OpenYurt have finer-grained division like node pool. This requires to dispatch some similar resources to the same cluster. These resources are called replication. Back to the example of OpenYurt, it can integrate KubeVela and replicate the resources then dispatch them to the different node pool.

    Usage

    Replication is an internal policy. It can be only used with deploy workflow step. When using replication policy. A new field replicaKey will be added to context. User can use definitions that make use of context.replicaKey. For example, apply a replica-webservice ComponentDefinition.

    In this ComponentDefinition, we can use context.replicaKey to distinguish the name of Deployment and Service.

    1. apiVersion: core.oam.dev/v1beta1
    2. kind: ComponentDefinition
    3. metadata:
    4. annotations:
    5. definition.oam.dev/description: Webservice, but can be replicated
    6. name: replica-webservice
    7. namespace: vela-system
    8. spec:
    9. schematic:
    10. cue:
    11. template: |
    12. output: {
    13. apiVersion: "apps/v1"
    14. kind: "Deployment"
    15. metadata: {
    16. if context.replicaKey != _|_ {
    17. name: context.name + "-" + context.replicaKey
    18. }
    19. if context.replicaKey == _|_ {
    20. name: context.name
    21. }
    22. }
    23. spec: {
    24. selector: matchLabels: {
    25. "app.oam.dev/component": context.name
    26. if context.replicaKey != _|_ {
    27. "app.oam.dev/replicaKey": context.replicaKey
    28. }
    29. }
    30. template: {
    31. metadata: {
    32. labels: {
    33. if parameter.labels != _|_ {
    34. parameter.labels
    35. }
    36. if parameter.addRevisionLabel {
    37. "app.oam.dev/revision": context.revision
    38. }
    39. "app.oam.dev/name": context.appName
    40. "app.oam.dev/component": context.name
    41. if context.replicaKey != _|_ {
    42. "app.oam.dev/replicaKey": context.replicaKey
    43. }
    44. }
    45. if parameter.annotations != _|_ {
    46. annotations: parameter.annotations
    47. }
    48. }
    49. }
    50. }
    51. }
    52. outputs: {
    53. if len(exposePorts) != 0 {
    54. webserviceExpose: {
    55. apiVersion: "v1"
    56. kind: "Service"
    57. metadata: {
    58. if context.replicaKey != _|_ {
    59. name: context.name + "-" + context.replicaKey
    60. }
    61. if context.replicaKey == _|_ {
    62. name: context.name
    63. }
    64. }
    65. spec: {
    66. selector: {
    67. "app.oam.dev/component": context.name
    68. if context.replicaKey != _|_ {
    69. "app.oam.dev/replicaKey": context.replicaKey
    70. }
    71. }
    72. ports: exposePorts
    73. type: parameter.exposeType
    74. }
    75. }
    76. }
    77. }

    Then user can apply application below. Replication policy is declared in application.spec.policies. These policies are used in deploy-with-rep workflow step. They work together to influence the deploy step.

    • override: select hello-rep component to deploy.
    • topology: select cluster local to deploy.
    • replication: select hello-rep component to replicate.

    As a result, there will be two Deployments and two Services:

    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: app-replication-policy
    5. spec:
    6. components:
    7. - name: hello-rep
    8. properties:
    9. image: crccheck/hello-world
    10. ports:
    11. - port: 80
    12. expose: true
    13. policies:
    14. - name: comp-to-replicate
    15. type: override
    16. properties:
    17. selector: [ "hello-rep" ]
    18. type: topology
    19. properties:
    20. clusters: [ "local" ]
    21. - name: replication-default
    22. type: replication
    23. properties:
    24. keys: ["beijing","hangzhou"]
    25. selector: ["hello-rep"]
    26. workflow:
    27. steps:
    28. - name: deploy-with-rep
    29. type: deploy
    30. properties:
    31. policies: ["comp-to-replicate","target-default","replication-default"]

    Specification (replication)

    NameDescriptionTypeRequiredDefault
    keysSpicify the keys of replication. Every key coresponds to a replication components.[]stringtrue
    selectorSpecify the components which will be replicated.[]stringfalse

    Shared-Resource

    Description

    Configure the resources to be sharable across applications.

    Examples (shared-resource)

    It’s used in shared-resource scenario. It can be used to configure which resources can be shared between applications. The target resource will allow multiple application to read it but only the first one to be able to write it.

    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: app1
    5. spec:
    6. components:
    7. - name: ns1
    8. type: k8s-objects
    9. properties:
    10. objects:
    11. - apiVersion: v1
    12. kind: Namespace
    13. metadata:
    14. name: example
    15. - name: cm1
    16. type: k8s-objects
    17. properties:
    18. objects:
    19. - apiVersion: v1
    20. kind: ConfigMap
    21. metadata:
    22. name: cm1
    23. namespace: example
    24. data:
    25. key: value1
    26. policies:
    27. - name: shared-resource
    28. type: shared-resource
    29. properties:
    30. rules:
    31. - selector:
    32. resourceTypes: ["Namespace"]
    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: app2
    5. spec:
    6. components:
    7. - name: ns2
    8. type: k8s-objects
    9. properties:
    10. objects:
    11. - apiVersion: v1
    12. kind: Namespace
    13. metadata:
    14. name: example
    15. - name: cm2
    16. type: k8s-objects
    17. properties:
    18. objects:
    19. - apiVersion: v1
    20. kind: ConfigMap
    21. metadata:
    22. name: cm2
    23. namespace: example
    24. data:
    25. key: value2
    26. policies:
    27. - name: shared-resource
    28. type: shared-resource
    29. properties:
    30. rules:
    31. - selector:
    32. resourceTypes: ["Namespace"]

    Specification (shared-resource)

    NameDescriptionTypeRequiredDefault
    rulesSpecify the list of rules to control shared-resource strategy at resource level.[]rulesfalse

    rules (shared-resource)

    NameDescriptionTypeRequiredDefault
    selectorSpecify how to select the targets of the rule.[]selectortrue
    selector (shared-resource)
    NameDescriptionTypeRequiredDefault
    componentNamesSelect resources by component names.[]stringfalse
    componentTypesSelect resources by component types.[]stringfalse
    oamTypesSelect resources by oamTypes (COMPONENT or TRAIT).[]stringfalse
    traitTypesSelect resources by trait types.[]stringfalse
    resourceTypesSelect resources by resource types (like Deployment).[]stringfalse
    resourceNamesSelect resources by their names.[]stringfalse

    Description

    Describe the destination where components should be deployed to.

    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: basic-topology
    5. namespace: examples
    6. spec:
    7. components:
    8. - name: nginx-basic
    9. type: webservice
    10. properties:
    11. image: nginx
    12. policies:
    13. - name: topology-hangzhou-clusters
    14. type: topology
    15. properties:
    16. clusters: ["hangzhou-1", "hangzhou-2"]
    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: local-ns-topology
    5. namespace: examples
    6. spec:
    7. components:
    8. - name: nginx-local-ns
    9. type: webservice
    10. properties:
    11. image: nginx
    12. policies:
    13. - name: topology-local
    14. type: topology
    15. properties:

    Specification (topology)