https://prefect.io logo
Title
j

Jacob Hall

03/15/2023, 7:08 PM
Hi there, I have a Kubernetes Job block defined with a set of customizations (JSON patches). I am looking to override some of these defaults on a per-deployment basis using infra_overrides. However, it appears that infra_overrides entirely overwrites key/values in the manifest, rather than patching them. This means I cannot keep some customizations and override others. Is this correct, and if so is there another way to apply JSON patches to a k8s job manifest on a per-deployment basis? Thanks in advance for your help!
r

redsquare

03/15/2023, 7:35 PM
you can just add to the list loaded from the block rather than overwrite it completely
j

Jacob Hall

03/15/2023, 7:49 PM
Thanks for your reply @redsquare. Looking at the loaded block, it seems that customizations are stored as a JsonPatch object, which may be difficult to modify and pass back into `prefect.deployments.Deployment.build_from_flow()`:
>>> from prefect.infrastructure.kubernetes import KubernetesJob
>>> job_block = KubernetesJob.load("my-k8s-block")
>>> type(job_block.customizations)
<class 'prefect.utilities.pydantic.JsonPatch'>
I'm willing to work with this, but wanted to see if there is an easier way. Another downside of this approach is that I'd have to re-deploy each of my deployments if I were to change the defaults in my Kubernetes Job block's customizations.
Building off my last comment:
job_block.customizations.patch
returns a list of patch dicts that I can add to and submit inside infra_overrides. Hooray! The big downside to this approach is that I'll have to re-deploy each time I update my infrastructure block (as noted above), but this is a workable solution.
r

redsquare

03/15/2023, 8:18 PM
you have to re-deploy on any change regardless, the k8s job is immutable at deployment time
its passed into the deploy and locked in as far as I know
j

Jacob Hall

03/15/2023, 8:23 PM
Oh, that is news to me! Indeed, if the infra block is made immutable in the deployment's eyes, this is all I can do. Thanks again.
👍 1