<@ULVA73B9P> in the job template of a kubernetes w...
# ask-marvin
l
@Marvin in the job template of a kubernetes work pool, can I use variables in templates that are not defined in the "variables" section of the file? e.g. can i use details about the flow, e.g. the flow run name?
m
thought for 74.8 seconds
Yes! You can absolutely use variables beyond those defined in the "variables" section of your work pool configuration. The Kubernetes work pool job templates have access to various runtime attributes about your flow run. Here are some of the commonly available variables you can use: -
{{ flow_run.name }}
- The name of the flow run -
{{ flow_run.id }}
- The unique identifier of the flow run -
{{ flow_run.flow_name }}
- The name of the flow -
{{ flow_run.parameters }}
- The parameters passed to the flow -
{{ deployment.name }}
- The name of the deployment -
{{ deployment.version }}
- The version of the deployment These variables are automatically injected into the context when the job template is rendered. You can use them in your job template like this:
Copy code
yaml
job_template:
  apiVersion: batch/v1
  kind: Job
  metadata:
    name: prefect-job-{{ flow_run.id }}
    labels:
      <http://prefect.io/flow-run-id|prefect.io/flow-run-id>: {{ flow_run.id }}
      <http://prefect.io/flow-run-name|prefect.io/flow-run-name>: {{ flow_run.name }}
  # ... rest of your job template
This is particularly useful for: - Creating unique job names - Adding labels or annotations for tracking/filtering - Setting environment variables based on flow run details - Configuring resource requests/limits dynamically Note that while these variables are available, it's still a good practice to: 1. Test your templates thoroughly, as some variables might be None in certain contexts 2. Consider using the
variables
section for values that you want to make easily configurable by users 3. Be cautious with special characters in variable values when using them in certain fields (like labels) that have strict naming requirements You can find more details about customizing job variables in the Prefect documentation.
l
can you provide a link to the docs where all the available variables are listed?
@Marvin can you provide a link to the docs where all the available variables are listed?
m
thought for 26.7 seconds
Based on my research and the GitHub issues, I have to acknowledge that there isn't currently a comprehensive documentation of all available template variables. This appears to be a documentation gap. What we do know for certain: 1. Variables defined in the
variables
section are accessed using
{{ variables.variable_name }}
2. Flow run details are available through
{{ flow_run.* }}
(as shown in the runtime module) 3. Deployment details are available through
{{ deployment.* }}
If you need to see exactly what variables are available in your specific context, you could: 1. Use the UI's Advanced tab in the work pool configuration to see the default template 2. Add a debug environment variable to your job template that prints out available variables 3. Check the runtime module reference for available attributes Would you like me to file a documentation issue requesting a comprehensive list of available template variables? This would be helpful for the community.