<@ULVA73B9P> What is the right way to set Pod labe...
# ask-marvin
s
@Marvin 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': .....
m
Based on the information from the Prefect documentation and related GitHub issues, it appears that correctly setting labels within the
KubernetesJob
job template can be challenging. There's not a clear solution provided in the official resources or in the issues mentioned. It's important to note that Kubernetes expects
metadata
to already exist when you apply a JSON patch to add labels. As for your error,
"member 'metadata' not found"
, it indicates that the JSON patch operation expected to find the
metadata
key in the base structure but didn't. One potential solution could be ensuring that you're patching an existing
metadata
block rather than attempting to add it where it doesn't exist. You may need to review the base Kubernetes Job definition used by Prefect to ensure it has a
metadata
section you can modify. Given the specifics of the issue, it may also be beneficial to explicitly request help from the Prefect community or report this issue on GitHub if you continue to encounter problems. For more in-depth assistance, consider reaching out: - Directly in the Prefect Slack community: Prefect Slack - Prefect GitHub Issues for potential bugs: Prefect GitHub Relevant Prefect documentation and issue links: - Developing a new worker type - Infrastructure Overview - Related GitHub Issue about labels not being applied in Kubernetes: Issue #11172 - GitHub Issue about adding annotations, similar to labels: Issue #8281
s
@Marvin I’m creating the base job manifest with
Copy code
from prefect.infrastructure.kubernetes import KubernetesJob

job = KubernetesJob()
Is there a way to add /spec/template/metadata path in order to modify it in future?