Skip to content

Latest commit

 

History

History
100 lines (58 loc) · 8.82 KB

6.traits.md

File metadata and controls

100 lines (58 loc) · 8.82 KB

6. Traits

A trait is a discretionary runtime overlay that augments a component workload instance with operational features. It represents an opportunity for those in the application operator role to make specific decisions about the configuration of components, without having to involve the component provider or breaking the component encapsulation.

For example, a sidecar trait that injects a sidecar container to the workload in WordPress Helm chart.

A trait can be any configuration of a distributed application that applies to an individual component, such as traffic routing rules (e.g., load balancing policy, network ingress routing, circuit breaking, rate limiting), auto-scaling policies, upgrade strategies, and more.

Trait Definition

This section is normative because traits are an inspectable (and possibly shareable) part of the system. All traits MUST be representable in the following format.

Traits are defined with schematics like components. As with workload definitions, each trait definition has a definitionRef, which is a reference to a schema that defines the configuration options for the trait.

Top-Level Attributes

The top-level attributes of a trait define its metadata, version, kind, and spec.

Attribute Type Required Default Value Description
apiVersion string Y A string that identifies the version of the schema the object should have. The core types uses core.oam.dev/v1beta1 in this version of specification.
kind string Y Must be TraitDefinition
metadata Metadata Y Information about the trait.
spec Spec Y A specification for trait attributes.

Spec

Attribute Type Required Default Value Description
appliesToWorkloads []string * The collection of workload type characteristics to which this trait applies. If this field is empty or unspecified or specified as "*", it means applies any workload type. A trait must apply to at least one workload type. This attribute must contain at least one value.
conflictsWith []string N A list of traits that would be conflict with this trait when applied to same workload type. For example, autoscaling may conflict with cron-autoscaling.
definitionRef DefinitionRef Y Identifier of the trait capability.

DefinitionRef

DefinitionRef identifies the trait capability, i.e. the trait implementation.

Attribute Type Required Default Value Description
name string N Name identifier of the trait. Mutually exclusive to apiVersion and kind.
apiVersion string N API version of the trait.
kind string N Kind of trait.

It's RECOMMENDED to use Group/Version/Kind to uniquely identify the trait capability. If using definitionRef.name, it MUST contain information that can be used to uniquely identify it.

The Application section will describe how a user can attach traits to component in detail.

Implementing a Trait System

WARNING: this section is for OAM platform implementors only, feel free to skip this section if you are only interested in the OAM concepts.

The traits system is defined in this specification as the way a runtime applies and manages operational behaviors to instances of components through traits.

Runtime implementations of the specification MUST provide the traits system for attaching operational behaviors to instances of components.

Traits System Rules and Characteristics

Traits SHOULD be applied into the runtime at installation/upgrade time. Traits SHOULD NOT be checked "lazily", but SHOULD be checked when the trait-holding components are created.

When more than one trait is attached to a component, it MUST:

  • Apply the traits in the defined order
  • Determine compatibility, and fail if the combination of traits cannot be satisfied

Traits are applied in order such that if some set of traits express dependency (e.g. ingress must be set up before SSL), this can be resolved by setting an explicit ordering.

A component instance may only have one configuration of any given trait type.

A deployment SHOULD NOT be marked complete until all trait configurations are completed. For example, if a web server component is deployed with an autoscaler trait, the web server should not be considered "running" until (a) the web server itself is running, as determined by health checks, and (b) the autosc