Add job_postprocessor hook to Kubernetes Job launchers - #309
Open
morgan-wowk wants to merge 1 commit into
Open
Conversation
The launchers already accept a pod_postprocessor to transform the Pod before launch, but there is no equivalent hook for the Job wrapper the PodOrJob and Job launchers create for multi-node runs — the only extension point was the no-op _transform_job_before_launching, reachable solely by subclassing the inner _KubernetesJobLauncher, which callers do not construct directly. Add a symmetric job_postprocessor: JobPostProcessor | None, threaded through _KubernetesJobLauncher, _KubernetesPodOrJobLauncher, and the two GKE launchers exactly like pod_postprocessor. The default _transform_job_before_launching now applies it when set and is otherwise a no-op, so existing launches are unchanged. This lets a caller set fields on the V1Job it cannot reach via the pod template — e.g. spec.ttlSecondsAfterFinished for native finished-Job cleanup on clusters without a Kueue/janitor reaper.
yuechao-qin
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Is it safe to deploy?
Yes — this is fully backward compatible.
job_postprocessoris a new keyword-only parameter defaulting toNone, so every existing launcher call site is unaffected and the Job-transform hook stays a no-op until a caller explicitly opts in.What
Adds a
job_postprocessorhook to the Kubernetes Job launchers, symmetric to the existingpod_postprocessor. It lets a caller transform theV1Jobobject right before it's created, threaded through_KubernetesJobLauncher,_KubernetesPodOrJobLauncher, and bothGoogleKubernetesEngine_UsingGoogleCloudStorage_*launchers.The default
_transform_job_before_launchingnow applies the injectedjob_postprocessorwhen one is set, and is otherwise the same no-op it was before.Why
The launchers already let callers customize the Pod (via
pod_postprocessor), and for multi-node runs that Pod becomes the Job's pod template — so pod-level changes already reach Job pods. But there was no way to set fields on theV1Jobitself without editing this repo:_transform_job_before_launchingwas a no-op override hook living on_KubernetesJobLauncher, but the class callers actually build is_KubernetesPodOrJobLauncher, which constructs a private inner_KubernetesJobLauncherwith no hook threaded through. So subclassing the public launcher can't reach it.The concrete need: a downstream (Tangle/oasis) execution cluster with no Kueue and a janitor that holds no
batch/jobspermission, so finished Job objects are never reaped. Stampingspec.ttlSecondsAfterFinishedlets Kubernetes' native TTL-after-finished controller clean them up — but that field is on the Job, not the pod template, sopod_postprocessorcan't set it. With this hook the caller does:System impact
job_postprocessordefaults toNone; the transform hook stays a no-op, so every existing launch path is byte-identical. New keyword-only param with a default → no call-site is required to change.Before / after
_KubernetesJobLauncher, which public callers don't instantiate → effectively not extensible.job_postprocessorthe same way they already passpod_postprocessor.Tests
tests/test_kubernetes_launchers.py(new, offline — no live K8s API or GCS):_transform_job_before_launchingapplies thejob_postprocessorwhen set;_KubernetesPodOrJobLauncherforwardsjob_postprocessorto its inner Job launcher.All pass;
black-formatted.