Custom Pod Manifests with String Templates
Customizing pod manifests with string templates is only supported by a ClearML Enterprise Server.
When launching a Kubernetes Pod to execute a ClearML Task, the ClearML Agent supports string templates. Templates can reference
ClearML system objects and runtime configuration values, using the following format: ${CLEARML_<variable-specifier>:<default-value>}.
For example, "${CLEARML_TASK.project}" will be replaced with the Task's project ID.
Single-value Variables
These variables resolve to a single value. You can use them directly in a template, without specifying any path.
For example "${CLEARML_QUEUE_NAME}" will be replaced with the name of the queue from which the task was pulled.
Available single-value variables:
QUEUE_NAME- Name of the queue from which the task is pulledQUEUE_ID- ID of the queue from which the task is pulledWORKER_ID- ID of the agent running the taskPROJECT_NAME- Task's project namePROJECT_ID- Task's project ID
Compound Variables (Path-Based)
These variables represent compound objects (mappings) for which you must specify a property path. Variable specifier is
in the format VARIABLE.path.to.property.
The following compound variables are supported:
TASK- Represents the ClearML Task objectdataproperty (seeTask.get_task()on how to get a task object in the SDK)USER- Represents the user data of the task's owner. In the ClearML SDK, use the following command to get user data:task.session.send_request("users", "get_current_user").json()['data']['user']`CONFIG- Represents the task’s configuration, as loaded from local configuration and associated user vaults. To get a section of the configuration object in the ClearML SDK, usetask.session.config.get("<section-name>")wheresection-namecan besdk,agent, or any other existing configuration section. You can also use custom fields that you added to your vaults.USER_VAULTS- Similar toCONFIG, but only includes configuration loaded from vaults applied for the user who’s the task owner.PROVIDERS_INFO- Contains user data retrieved from the identity provider (SSO), if configured on the ClearML Server.
List Type Variables
If a variable resolves to a list of simple values (e.g. string or number), it is expanded as a comma-separated list of values.
For example, if a task has the tags ["tag1", "tag2", "tag3"], the variable ${CLEARML_TASK.tags} expands to tag1,tag2,tag3.
Examples
${CLEARML_TASK.name}
${CLEARML_TASK.id}
${CLEARML_TASK.project}
${CLEARML_TASK.hyperparams.properties.user_key.value}
Default Fallback
Use a colon (:) to define a default fallback string for when the variable does not have a value.
For example:
${CLEARML_TASK.hyperparams.properties.user_key.value:myDefault}
If user_key is not set, the string will resolve to myDefault.
Filter Operators
Templates also support filter operators that can modify the resulting value strings.
Filter operators are applied using a pipe (|) followed by the function name, in the format
"${CLEARML_<variable-specifier>...|op1|op2|op3(x)}". This is also compatible with default fallbacks.
Available Operators
strip(chars)- Remove the listed characters. For example,strip(abcd)removesa,b,cord. Empty argument will strip white-spaces.capitalize- Capitalize the stringlower- Convert string to lowercaseremove_newlines- Remove newlinesraw- Keep newlines
When no filter operators are specified, remove_newlines operator is applied by default.
Using Templates in ClearML Agent Helm Chart
String templates customization is supported under the basePodTemplate and templateOverrides properties of the ClearML
Agent values.
For example:
agentk8sglue:
basePodTemplate:
labels:
myTaskName: "${CLEARML_TASK.name}"
myProjectId: "${CLEARML_TASK.project}"
queues:
myQueueName:
templateOverrides:
labels:
team: "green"
env:
- name: "userKey"
value: "${CLEARML_USER_VAULTS.my_section.userKey:undefined_user_key}"