Workload Definition Spec
This page describes every field of a Workload Map definition: its type, whether it is required, and what it does. A definition is a Karta resource in the run.ai/v1alpha1 API. To write a definition, refer to Define a Workload Type.
The Karta Resource
A Karta resource is cluster-scoped. Its plural name is kartas, and its short name is krt. The following command lists the definitions in a cluster. The columns show the kind of the root component, its name, and the age of the definition:
A definition has the standard apiVersion, kind, and metadata fields, a spec, and a status. The Karta Operator writes the status. For more information, refer to Definition Status.
Paths
Every path in a definition is a jq expression. jq provides path navigation and queries, and it is widely used in the Kubernetes ecosystem. Follow these rules for paths:
- Use a jq expression of the matching type for every property.
- Write absolute paths from the root of the resource.
- Provide default values where a field can be absent, for example
.status.active // 0. This keeps the expression null-safe. - Know which object a path is evaluated against. Paths in
specDefinition,scaleDefinition, andstatusDefinitionare evaluated against the workload object. Paths inpodSelectorand inoptimizationInstructionsare evaluated against the manifest of a pod.
spec
structureDefinition
The structureDefinition field describes the hierarchy of the workload as a root component and its child components.
additionalChildKinds
List the kinds of objects that the workload creates or manages and that no component names. The list is required for RBAC purposes. Do not list a kind that a component already declares.
Each entry has the fields of a group, version, and kind:
Components
The root component is the top-level resource of the workload. Every definition must have one. A child component is a resource that the root component owns.
The following rules apply:
- The root component must use the full group, version, and kind, and it must have a
statusDefinition. - A child component must have an
ownerRefthat names its parent component. - A child component usually has a
specDefinition. - All paths are absolute from the root of the resource.
The kind field of a component has the following fields. The core Pod kind has an empty group:
The following example shows a root component and a child component:
specDefinition
The specDefinition field tells Workload Map where a component stores its pods. The patterns are mutually exclusive. Use exactly one for each component:
fragmentedPodSpecDefinition
For example:
scaleDefinition
Component Instances
The specDefinition of a component can point to several instances of pod specs, in an array or a map. To tell the instances apart, set an instanceIdPath. It is the location in the spec where the name of each instance is. For an array of specs:
For a map of specs, extract the keys of the map as the instance IDs:
podSelector
The podSelector field defines how to identify the pods of a component, or of an instance of a component. A component can define both a type selector and an instance selector. All selectors of each kind must be mutually exclusive within themselves. Paths in pod selectors refer to paths in the manifest of the pod.
componentTypeSelector
A key and a value selector that associates a pod with the component. If you omit value, the selector checks only that the key exists.
componentInstanceSelector
replicaSelector
statusDefinition
The statusDefinition field maps the conditions or phases of the workload to the common statuses of Workload Map. Base it on the actual conditions or phases that the workload type uses. It is required on the root component.
- For each common status, you can provide a rule that uses conditions, a phase, or an expression. If you provide both a phase and conditions, both must match.
- If you use a rule by conditions, you must first provide a
conditionsDefinition. If you use a rule by phase, you must first provide aphaseDefinition. - You can provide several separate rules for each status. The rules are ORed together.
- All conditions in a
byConditionsrule must match. - A workload can match more than one status at the same time. When no rule matches, the status is
Undefined.
conditionsDefinition
phaseDefinition
statusMappings
Each field is a list of matchers for one status. The statuses are initializing, running, completed, failed, degraded, suspended, suspending, and resuming.
Each matcher has the following fields:
byConditions
byExpression
The following example maps a workload that reports its state in conditions:
suspendDefinition
Set a suspendDefinition only for a component where the framework supports suspension natively. For example, a Job has .spec.suspend.
Each action has the following fields:
optimizationInstructions
The optimizationInstructions field is for schedulers. Paths in the instructions refer to paths in the manifest of the pod. The supported instruction is gangScheduling, which tells the scheduler how to group the pods of the workload.
This part of the API is experimental and may change.
podGroup
subGroups
topology
The topology field has the same fields at the pod group level and at the subgroup level:
podGroups
The podGroups list is the older format. It is deprecated in favor of podGroup, and it will be removed in a future release. The two formats are not equivalent. A subgroup has only componentName and topology, so the groupByKeyPaths and filters of a member have no direct counterpart.
members
Each member of a pod group has the following fields. Each member can provide a list of distinct keys to group the pods by, and a list of filters that decide which pods to include.
The following examples use the older format.
Different hierarchy. The following two definitions are equivalent, if master and worker have the same value for the label:
Default values. When several groups are possible, use a default value to cover the case where there is a single group. The pattern is <prefix>-{name}-{index}:
Filters. When the components are not named components, because an array or a map of specs is in the same component, use filters to form separate pod groups. In the following example, a CRD defines several jobs, all under the job component. A jq query as a filter finds the pods that use NVIDIA GPUs, and queries with hard-coded values are the grouping keys:
Definition Status
The Karta Operator writes the status of a definition. It has a conditions list with the following conditions:
The Karta Operator also stamps the labels karta.run.ai/group, karta.run.ai/version, and karta.run.ai/kind on every definition that has a root component kind. They hold the group, version, and kind of the root component. A webhook rejects an edit that changes or removes these labels.
Best Practices
- Use the full group, version, and kind for every kind.
- Use absolute paths only in spec definitions.
- Do not list a component that is defined explicitly in
additionalChildKinds. - Make the pod selectors mutually exclusive in a workload with several components.
- Write null-safe jq expressions, for example with
// 0defaults. - Target the actual components in optimization instructions, not only the root CRD.
Examples
For complete definitions, refer to the Catalog of Definitions.