Skip to main content

prefect_kubernetes.jobs

Module to define tasks for interacting with Kubernetes jobs.

Functions

create_namespaced_job

create_namespaced_job(kubernetes_credentials: KubernetesCredentials, new_job: Union[V1Job, Dict[str, Any]], namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job
Task for creating a namespaced Kubernetes job. Args:
  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • new_job: A Kubernetes V1Job specification.
  • namespace: The Kubernetes namespace to create this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).
Returns:
  • A Kubernetes V1Job object.

delete_namespaced_job

delete_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, delete_options: Optional[V1DeleteOptions] = None, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Status
Task for deleting a namespaced Kubernetes job. Args:
  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to delete.
  • delete_options: A Kubernetes V1DeleteOptions object.
  • namespace: The Kubernetes namespace to delete this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).
Returns:
  • A Kubernetes V1Status object.

list_namespaced_job

list_namespaced_job(kubernetes_credentials: KubernetesCredentials, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1JobList
Task for listing namespaced Kubernetes jobs. Args:
  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • namespace: The Kubernetes namespace to list jobs from.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).
Returns:
  • A Kubernetes V1JobList object.

patch_namespaced_job

patch_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, job_updates: V1Job, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job
Task for patching a namespaced Kubernetes job. Args:
  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to patch.
  • job_updates: A Kubernetes V1Job specification.
  • namespace: The Kubernetes namespace to patch this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).
Raises:
  • ValueError: if job_name is None.
Returns:
  • A Kubernetes V1Job object.

read_namespaced_job

read_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job
Task for reading a namespaced Kubernetes job. Args:
  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to read.
  • namespace: The Kubernetes namespace to read this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).
Raises:
  • ValueError: if job_name is None.
Returns:
  • A Kubernetes V1Job object.

replace_namespaced_job

replace_namespaced_job(kubernetes_credentials: KubernetesCredentials, job_name: str, new_job: V1Job, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job
Task for replacing a namespaced Kubernetes job. Args:
  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to replace.
  • new_job: A Kubernetes V1Job specification.
  • namespace: The Kubernetes namespace to replace this job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).
Returns:
  • A Kubernetes V1Job object.

read_namespaced_job_status

read_namespaced_job_status(kubernetes_credentials: KubernetesCredentials, job_name: str, namespace: Optional[str] = 'default', **kube_kwargs: Dict[str, Any]) -> V1Job
Task for fetching status of a namespaced Kubernetes job. Args:
  • kubernetes_credentials: KubernetesCredentials block holding authentication needed to generate the required API client.
  • job_name: The name of a job to fetch status for.
  • namespace: The Kubernetes namespace to fetch status of job in.
  • **kube_kwargs: Optional extra keyword arguments to pass to the Kubernetes API (e.g. {"pretty"\: "...", "dry_run"\: "..."}).
Returns:
  • A Kubernetes V1JobStatus object.

Classes

KubernetesJobRun

A container representing a run of a Kubernetes job. Methods:

afetch_result

afetch_result(self) -> Dict[str, Any]
Async implementation: fetch the results of the job. Returns:
  • The logs from each of the pods in the job.
Raises:
  • ValueError: If this method is called when the job has a non-terminal state.

await_for_completion

await_for_completion(self, print_func: Optional[Callable] = None)
Async implementation: waits for the job to complete. If the job has delete_after_completion set to True, the job will be deleted if it is observed by this method to enter a completed state. Raises:
  • RuntimeError: If the Kubernetes job fails.
  • KubernetesJobTimeoutError: If the Kubernetes job times out.

fetch_result

fetch_result(self) -> Dict[str, Any]
Fetch the results of the job. Returns:
  • The logs from each of the pods in the job.
Raises:
  • ValueError: If this method is called when the job has a non-terminal state.

v1_job_model

v1_job_model(self) -> dict[str, Any]

wait_for_completion

wait_for_completion(self, print_func: Optional[Callable] = None)
Waits for the job to complete. If the job has delete_after_completion set to True, the job will be deleted if it is observed by this method to enter a completed state. Raises:
  • RuntimeError: If the Kubernetes job fails.
  • KubernetesJobTimeoutError: If the Kubernetes job times out.

KubernetesJob

A block representing a Kubernetes job configuration. Methods:

atrigger

atrigger(self)
Async implementation: create a Kubernetes job and return a KubernetesJobRun object.

from_yaml_file

from_yaml_file(cls: Type[Self], manifest_path: Union[Path, str], **kwargs) -> Self
Create a KubernetesJob from a YAML file. Args:
  • manifest_path: The YAML file to create the KubernetesJob from.
Returns:
  • A KubernetesJob object.

trigger

trigger(self)
Create a Kubernetes job and return a KubernetesJobRun object.