Hello :wave: What is the right way to set Pod lab...
# ask-community
s
Hello πŸ‘‹ What is the right way to set Pod labels inside Job template? Have tried
Copy code
from prefect.infrastructure.kubernetes import KubernetesJob
job = KubernetesJob()
job.customizations = jsonpatch.JsonPatch([

    {
        'op': 'add',
        'path': '/spec/template/metadata/labels',
        'value': {
            '<http://app.kubernetes.io/instance|app.kubernetes.io/instance>': 'prefect-agent'
        }
    }
])
...
But all I got was:
Copy code
jsonpointer.JsonPointerException: member 'metadata' not found in {'spec': {'containers': [{'env': [{'name': .....
Should it be something like:
Copy code
{
        'op': 'add',
        'path': '/spec/template',
        'value': { 
            'metadata': {
                'labels': {
                    '<http://app.kubernetes.io/instance|app.kubernetes.io/instance>': 'prefect-agent'
                }
            }
        }
    }
Or there is more elegant solution?
πŸ™… 1
Any help appreciatedπŸ™
h
In case you are still stuck, maybe this helps https://discourse.prefect.io/t/use-aks-workload-identity/3354? I have been able to add labels to my prefect flow pods using this. The code for the job template is almost at the end of the writeup.
πŸ‘€ 1
s
Actually made a bit of another move. Patching (customizing) won’t work since the item is not created. So I rewrote the whole base job manifest with
job.job
object https://docs.prefect.io/latest/api-ref/prefect/infrastructure/#prefect.infrastructure.KubernetesJob Worked for me..