https://prefect.io logo
b

Billy McMonagle

01/27/2021, 2:21 AM
I have a question regarding
KubernetesRun
... is there a direct way to set metadata labels on the flow run job/pod, or is a custom job template necessary? I'm specifically interested in tagging my jobs so that datadog is able to collect metrics.
This seems to work but I'm not sure whether it is the recommended/simplest approach:
Copy code
job_template = """
apiVersion: batch/v1
kind: Job
metadata:
  name: prefect-job
  labels:
    <http://tags.datadoghq.com/service|tags.datadoghq.com/service>: xxxxxxx
spec:
  template:
    metadata:
      <http://tags.datadoghq.com/service|tags.datadoghq.com/service>: xxxxxxx
    spec:
      containers:
        - name: flow
"""

environment_variables = {"FOO": "BAR"}
service_account_name = "my-service-account"
run_config = KubernetesRun(
    env=environment_variables, service_account_name=service_account_name, job_template=job_template
)
j

Jim Crist-Harif

01/27/2021, 3:03 AM
A custom template is required. This can either be set on the
KubernetesRun
object (as you've done), or on the agent by passing in
--job-template
(which will be used by default for all flows run by that agent).
b

Billy McMonagle

01/27/2021, 3:10 AM
awesome thanks @Jim Crist-Harif!
c

Chris White

01/27/2021, 4:50 PM
@Marvin archive “How to add custom annotations to my Kubernetes jobs”