Definition Objects
This documentation explains ComponentDefinition
and TraitDefinition
in detail.
#
OverviewEssentially, a definition object in KubeVela is a programmable build block. A definition object normally includes several information to model a certain platform capability that would used in further application deployment:
- Capability Indicator
ComponentDefinition
usesspec.workload
to indicate the workload type of this component.TraitDefinition
usesspec.definitionRef
to indicate the provider of this trait.
- Interoperability Fields
- they are for the platform to ensure a trait can work with given workload type. Hence only
TraitDefinition
has these fields.
- they are for the platform to ensure a trait can work with given workload type. Hence only
- Capability Encapsulation and Abstraction defined by
spec.schematic
- this defines the templating and parametering (i.e. encapsulation) of this capability.
Hence, the basic structure of definition object is as below:
Let's explain these fields one by one.
#
Capability IndicatorIn ComponentDefinition
, the indicator of workload type is declared as spec.workload
.
Below is a definition for Web Service in KubeVela:
In above example, it claims to leverage Kubernetes Deployment (apiVersion: apps/v1
, kind: Deployment
) as the workload type for component.
#
Interoperability FieldsThe interoperability fields are trait only. An overall view of interoperability fields in a TraitDefinition
is show as below.
Let's explain them in detail.
.spec.appliesToWorkloads
#
This field defines the constraints that what kinds of workloads this trait is allowed to apply to.
- It accepts an array of string as value.
- Each item in the array refers to one or a group of workload types to which this trait is allowed to apply.
There are four approaches to denote one or a group of workload types.
ComponentDefinition
name, e.g.,webservice
,worker
ComponentDefinition
definition reference (CRD name), e.g.,deployments.apps
- Resource group of
ComponentDefinition
definition reference prefixed with*.
, e.g.,*.apps
,*.oam.dev
. This means the trait is allowed to apply to any workloads in this group. *
means this trait is allowed to apply to any workloads
If this field is omitted, it means this trait is allowed to apply to any workload types.
KubeVela will raise an error if a trait is applied to a workload which is NOT included in the appliesToWorkloads
.
.spec.conflictsWith
#
This field defines that constraints that what kinds of traits are conflicting with this trait, if they are applied to the same workload.
- It accepts an array of string as value.
- Each item in the array refers to one or a group of traits.
There are four approaches to denote one or a group of workload types.
TraitDefinition
name, e.g.,ingress
- Resource group of
TraitDefinition
definition reference prefixed with*.
, e.g.,*.networking.k8s.io
. This means the trait is conflicting with any traits in this group. *
means this trait is conflicting with any other trait.
If this field is omitted, it means this trait is NOT conflicting with any traits.
.spec.workloadRefPath
#
This field defines the field path of the trait which is used to store the reference of the workload to which the trait is applied.
- It accepts a string as value, e.g.,
spec.workloadRef
.
If this field is set, KubeVela core will automatically fill the workload reference into target field of the trait. Then the trait controller can get the workload reference from the trait latter. So this field usually accompanies with the traits whose controllers relying on the workload reference at runtime.
Please check scaler trait as a demonstration of how to set this field.
.spec.podDisruptive
#
This field defines that adding/updating the trait will disruptive the pod or not.
In this example, the answer is not, so the field is false
, it will not affect the pod when the trait is added or updated.
If the field is true
, then it will cause the pod to disruptive and restart when the trait is added or updated.
By default, the value is false
which means this trait will not affect.
Please take care of this field, it's really important and useful for serious large scale production usage scenarios.
#
Capability Encapsulation and AbstractionThe programmable template of given capability are defined in spec.schematic
field. For example, below is the full definition of Web Service type in KubeVela:
The specification of schematic
is explained in following CUE and Helm specific documentations.
Also, the schematic
filed enables you to render UI forms directly based on them, please check the Generate Forms from Definitions section about how to.
#
Definition RevisionsIn KubeVela, definition entities are mutable. Each time a ComponentDefinition
or TraitDefinition
is updated, a corresponding DefinitionRevision
will be generated to snapshot this change. Hence, KubeVela allows user to reference a specific revision of definition to declare an application.
For example, we can design a new parameter named args
for the webservice
component definition by applying a new definition with same name as below.
The change will take effect immediately.
We will see a new definition revision will be automatically generated, v2
is the latest version, v1
is the previous one.
#
Specify Definition Revision in ApplicationUsers can specify the revision with @version
approach, for example, if a user want to stick to using the v1
revision of webservice
component:
If no revision is specified, KubeVela will always use the latest revision for a given component definition.