Skip to navigation

Workload Definition Spec

View as MarkdownOpen in Claude

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:

kubectl get krt

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.

apiVersion: run.ai/v1alpha1
kind: Karta
metadata:
name: batch-v1-job
spec:
structureDefinition:
rootComponent:
name: job
kind:
group: batch
version: v1
kind: Job

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, and statusDefinition are evaluated against the workload object. Paths in podSelector and in optimizationInstructions are evaluated against the manifest of a pod.

spec

FieldTypeRequiredDescription
experimentalbooleanNoMarks definitions that consumers must explicitly enable.
optimizationInstructionsobjectNoContains the optimization instructions for the workload.
structureDefinitionobjectYesDefines the compute hierarchy and component relationships.

structureDefinition

The structureDefinition field describes the hierarchy of the workload as a root component and its child components.

FieldTypeRequiredDescription
additionalChildKindsarray of objectsNoLists Kubernetes kinds that are created/managed by this workload but are not explicitly modeled as components (for example, Deployments and Services). The list is required for RBAC purposes.
childComponentsarray of objectsNoDefines the child components in the hierarchy.
rootComponentobjectYesDefines the top-level component of the workload hierarchy.

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.

additionalChildKinds:
- group: apps
version: v1
kind: Deployment
- group: leaderworkerset.x-k8s.io
version: v1
kind: LeaderWorkerSet

Each entry has the fields of a group, version, and kind:

FieldTypeRequiredDescription
groupstringYesThe API group of the resource.
kindstringYesThe API kind of the resource.
versionstringYesThe API version of the resource.

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.

FieldTypeRequiredDescription
instanceIdPathstringNoThe JQ path to the instance id, for components that hold multiple pod definitions (in an array or a map).
kindobjectNoSpecifies the Kubernetes GroupVersionKind for this component.
namestringYesThe unique identifier for this component within the Karta.
ownerRefstringNoReferences the parent component in the hierarchy by name (not set for the root component).
podSelectorobjectNoDefines how to identify pods belonging to this component.
scaleDefinitionobjectNoDefines how to extract scaling information from this component.
specDefinitionobjectNoDefines how to extract pod specifications from this component.
statusDefinitionobjectNoDefines how to interpret the status of this component. Set it only on the root component.
suspendDefinitionobjectNoDefines the path/value assignments used to suspend and resume this component. Should only be populated for components where the underlying framework provides native, first-class support for suspension primitives. (for example, spec.suspend for a batch/v1 Job).

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 ownerRef that 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:

FieldTypeRequiredDescription
groupstringYesThe API group of the resource.
kindstringYesThe API kind of the resource.
versionstringYesThe API version of the resource.

The following example shows a root component and a child component:

rootComponent:
name: "pytorchjob"
kind:
group: "kubeflow.org"
version: "v1"
kind: "PyTorchJob"
statusDefinition:
statusMappings:
running:
- byConditions:
- type: "Running"
status: "True"
childComponents:
- name: "worker"
ownerRef: "pytorchjob"
kind:
group: "apps"
version: "v1"
kind: "StatefulSet"
specDefinition:
podTemplateSpecPath: ".spec.pytorchReplicaSpecs.Worker.template"

specDefinition

The specDefinition field tells Workload Map where a component stores its pods. The patterns are mutually exclusive. Use exactly one for each component:

PatternUse caseExample path
podTemplateSpecPathThe resource embeds a full pod template..spec.pytorchReplicaSpecs.Master.template
podSpecPath and metadataPathThe resource embeds a pod spec, an object metadata, or both..spec.jobTemplate.spec and .spec.jobTemplate.metadata
fragmentedPodSpecDefinitionThe pod fields are scattered across the resource.See the following table.
FieldTypeRequiredDescription
fragmentedPodSpecDefinitionobjectNoDefines how to extract individual pod spec fields when they are scattered across different paths in the component.
metadataPathstringNoThe JQ path to the component metadata. Use it only with PodSpecPath, when the pod spec and the metadata are separate.
podSpecPathstringNoThe JQ path to a complete PodSpec object.
podTemplateSpecPathstringNoThe JQ path to a complete PodTemplateSpec object.

fragmentedPodSpecDefinition

FieldTypeRequiredDescription
annotationsPathstringNoThe JQ path to pod annotations.
containerPathstringNoThe JQ path to the specification of a single container. Use it when the component has only one container.
containersPathstringNoThe JQ path to the specifications of the containers.
imagePathstringNoThe JQ path to the container image.
labelsPathstringNoThe JQ path to pod labels.
nodeAffinityPathstringNoThe JQ path to node affinity rules.
podAffinityPathstringNoThe JQ path to pod affinity rules.
priorityClassNamePathstringNoThe JQ path to the priority class name.
resourceClaimsPathstringNoThe JQ path to DRA resource claims.
resourcesPathstringNoThe JQ path to resource requirements.
schedulerNamePathstringNoThe JQ path to the scheduler name.

For example:

specDefinition:
fragmentedPodSpecDefinition:
labelsPath: ".spec.labels"
annotationsPath: ".spec.annotations"
resourcesPath: ".spec.resources"
schedulerNamePath: ".spec.schedulerName"

scaleDefinition

FieldTypeRequiredDescription
maxReplicasPathstringNoThe JQ path to the maximum replica count.
minReplicasPathstringNoThe JQ path to the minimum replica count.
replicasPathstringNoThe JQ path to the current replica count.

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:

instanceIdPath: ".spec.jobs[].name"

For a map of specs, extract the keys of the map as the instance IDs:

instanceIdPath: ".spec.jobs | to_entries[] | .key"

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.

FieldTypeRequiredDescription
componentInstanceSelectorobjectNoSplits a single ComponentDefinition into multiple component instances, each identified by a unique value extracted from the pod. Use this when instances of the same component type represent fundamentally different roles or services (for example, Dynamo “service” definition produces separate “Frontend”, “PrefillWorker”, “DecodeWorker” instances). This is distinct from ReplicaSelector: ComponentInstanceSelector creates instances with potentially different specs/behavior, while ReplicaSelector creates replicas of an identical sub-structure.
componentTypeSelectorobjectNoDetermines whether a pod belongs to this component type by matching a pod label or annotation value via a JQ path. This is the primary mechanism for pod-to-component membership. For example, LWS “leader” uses worker-index=“0” to identify leader pods, and LWS “worker” checks for the existence of the leader-name annotation.
replicaSelectorobjectNoIdentifies which replica index or group the pod belongs to. Use this to distinguish between multiple replicas of the same component / component instance sub-structure (for example, LWS Group 0 vs Group 1, where each group has identical leader/worker descendants). Descendant components automatically inherit the replica context from their ancestor (parent), so ReplicaSelector should only be defined at the level where replicas are created, not repeated in descendants.

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.

FieldTypeRequiredDescription
keyPathstringYesThe JQ path to the identifying key/label on the pod. The JQ path is evaluated against individual pod objects, not the root resource spec.
valuestringNoThe expected value for the key (optional). If it is not set, only the existence of the key is checked.
podSelector:
componentTypeSelector:
keyPath: '.metadata.labels["training.kubeflow.org/replica-type"]'
value: "master"

componentInstanceSelector

FieldTypeRequiredDescription
idPathstringYesThe JQ path to the component instance identifier on the pod. The JQ path is evaluated against individual pod objects, not the root resource spec.
podSelector:
componentInstanceSelector:
idPath: '.metadata.labels["jobset.sigs.k8s.io/replicatedjob-name"]'

replicaSelector

FieldTypeRequiredDescription
keyPathstringYesThe JQ path to the replica identifier on the pod. The evaluated result should be the replica index or group identifier (for example, “0”, “1”).

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 a phaseDefinition.
  • You can provide several separate rules for each status. The rules are ORed together.
  • All conditions in a byConditions rule must match.
  • A workload can match more than one status at the same time. When no rule matches, the status is Undefined.
FieldTypeRequiredDescription
conditionsDefinitionobjectNoDefines how to extract Kubernetes-style conditions.
phaseDefinitionobjectNoDefines how to extract a simple phase/state string.
statusMappingsobjectYesDefines how to map extracted status to ResourceStatus values.

conditionsDefinition

FieldTypeRequiredDescription
messageFieldNamestringNoThe field name for the condition text message.
pathstringYesThe JQ path to the conditions array.
reasonFieldNamestringNoThe field name for the condition reason.
statusFieldNamestringNoThe field name for the condition status.
typeFieldNamestringNoThe field name for the condition type.

phaseDefinition

FieldTypeRequiredDescription
pathstringYesThe JQ path to the phase/state field.

statusMappings

Each field is a list of matchers for one status. The statuses are initializing, running, completed, failed, degraded, suspended, suspending, and resuming.

FieldTypeRequiredDescription
completedarray of objectsNoDefines matchers for the Completed status. Multiple matchers are ORed together.
degradedarray of objectsNoDefines matchers for the Degraded status. Multiple matchers are ORed together.
failedarray of objectsNoDefines matchers for the Failed status. Multiple matchers are ORed together.
initializingarray of objectsNoDefines matchers for the Initializing status. Multiple matchers are ORed together.
resumingarray of objectsNoDefines matchers for the Resuming status. Multiple matchers are ORed together.
runningarray of objectsNoDefines matchers for the Running status. Multiple matchers are ORed together.
suspendedarray of objectsNoDefines matchers for the Suspended status. Multiple matchers are ORed together.
suspendingarray of objectsNoDefines matchers for the Suspending status. Multiple matchers are ORed together.

Each matcher has the following fields:

FieldTypeRequiredDescription
byConditionsarray of objectsNoMatches against specific condition combinations (ANDed together). At least one of status or reason must be used.
byExpressionobjectNoA JQ expression that matches against the object for status matching.
byPhasestringNoMatches against a specific phase value.

byConditions

FieldTypeRequiredDescription
reasonstringNoThe expected condition reason.
statusstringNoThe expected condition status.
typestringYesThe condition type to match.

byExpression

FieldTypeRequiredDescription
expectedResultstringYesThe expected result value in string format from the expression evaluation.
expressionstringYesThe JQ expression to evaluate.

The following example maps a workload that reports its state in conditions:

statusDefinition:
conditionsDefinition:
path: ".status.conditions"
typeFieldName: "type"
statusFieldName: "status"
statusMappings:
initializing:
- byConditions:
- type: "Created"
status: "True"
- type: "Running"
status: "False"
running:
- byConditions:
- type: "Running"
status: "True"
- type: "Succeeded"
status: "False"
- type: "Failed"
status: "False"
completed:
- byConditions:
- type: "Succeeded"
status: "True"
failed:
- byConditions:
- type: "Failed"
status: "True"

suspendDefinition

Set a suspendDefinition only for a component where the framework supports suspension natively. For example, a Job has .spec.suspend.

FieldTypeRequiredDescription
resumeActionsarray of objectsYesAn ordered list of path/value assignments applied on resume. Actions are applied in sequence; later actions may overwrite earlier ones.
suspendActionsarray of objectsYesAn ordered list of path/value assignments applied on suspend. Actions are applied in sequence; later actions may overwrite earlier ones.

Each action has the following fields:

FieldTypeRequiredDescription
pathstringYesA JQ expression that selects the target field (for example, “.spec.suspend”). Only read/navigation expressions are permitted; assignment operators are not.
valuestringYesThe JSON-encoded value to assign at the path (for example, “true”, “0”, "paused", “null”).

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.

Experimental

This part of the API is experimental and may change.

FieldTypeRequiredDescription
podGroupobjectNoDefines the grouping, subgroup, and topology behavior.
podGroupsarray of objectsNoDefines the alpha grouping format. This is deprecated and will be removed in a future release. Deprecated: Please use gangScheduling.podGroup instead.

podGroup

FieldTypeRequiredDescription
namestringYesThe unique identifier for this pod group.
subGroupsarray of objectsNoDefines which Karta components should become subGroups.
topologyobjectNoDefines the topology constraint for all workload pods.

subGroups

FieldTypeRequiredDescription
componentNamestringYesReferences a component defined in the Karta structure.
topologyobjectNoDefines the topology constraint for this component’s pods.

topology

The topology field has the same fields at the pod group level and at the subgroup level:

FieldTypeRequiredDescription
preferredTopologyLevelstringYesThe preferred locality level.
requiredTopologyLevelstringYesThe maximal level that all matching pods must fit within.
topologyNamestringYesThe topology resource used by the constraint.
optimizationInstructions:
gangScheduling:
podGroup:
name: job
subGroups:
- componentName: job

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.

FieldTypeRequiredDescription
membersarray of objectsYesDefines which components belong to this pod group.
namestringYesThe unique identifier for this pod group.

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.

FieldTypeRequiredDescription
componentNamestringYesReferences a component defined in the Karta structure.
filtersarray of stringNoJQ filter expressions to select specific components (expressions are ANDed). Example: ‘(.spec.containers[0].resources.limits[“nvidia.com/gpu”] // 0) > 0’ JQ filters are evaluated against individual pod objects, not the root resource spec.
groupByKeyPathsarray of stringNoJQ paths to values used for grouping (for example, the owner name or the replica key). If empty, grouping is done via owner reference traversal. Every path must return a single, non-empty value - otherwise grouping fails. JQ paths are evaluated against individual pod objects, not the root resource spec.

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:

optimizationInstructions:
gangScheduling:
podGroups:
- name: "job"
members:
- componentName: "master"
groupByKeyPaths:
- '.metadata.labels["training.kubeflow.org/job-name"]'
- componentName: "worker"
groupByKeyPaths:
- '.metadata.labels["training.kubeflow.org/job-name"]'
optimizationInstructions:
gangScheduling:
podGroups:
- name: "job"
members:
- componentName: "job"
groupByKeyPaths:
- '.metadata.labels["training.kubeflow.org/job-name"]'

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}:

optimizationInstructions:
gangScheduling:
podGroups:
- name: "group"
members:
- componentName: "group"
groupByKeyPaths:
- '.metadata.labels["leaderworkerset.sigs.k8s.io/name"]'
- '.metadata.labels["leaderworkerset.sigs.k8s.io/group-index"] // "0"'

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:

optimizationInstructions:
gangScheduling:
podGroups:
- name: "gpu-jobs"
members:
- componentName: "job"
filters:
- 'any(.spec.jobs[].spec.containers[]; (.resources.limits["nvidia.com/gpu"] // 0) > 0)'
groupByKeyPaths:
- 'gpu'
- name: "no-gpu-jobs"
members:
- componentName: "job"
filters:
- 'any(.spec.jobs[].spec.containers[]; (.resources.limits["nvidia.com/gpu"] // 0) == 0)'
groupByKeyPaths:
- 'no-gpu'

Definition Status

The Karta Operator writes the status of a definition. It has a conditions list with the following conditions:

ConditionIt is True when
ValidatedThe definition passes validation.
CRDExistsThe cluster has the CRD for the root component of the definition, and the CRD serves the version that the definition names.
ReadyBoth Validated and CRDExists are True.

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 // 0 defaults.
  • Target the actual components in optimization instructions, not only the root CRD.

Examples

For complete definitions, refer to the Catalog of Definitions.