Skip to main content

prefect_kubernetes.jobs

Module to define tasks for interacting with Kubernetes jobs.

Functions

create_namespaced_job

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

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

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

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

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

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

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

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

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 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

wait_for_completion

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

Async implementation: create a Kubernetes job and return a KubernetesJobRun object.

from_yaml_file

Create a KubernetesJob from a YAML file. Args:
  • manifest_path: The YAML file to create the KubernetesJob from.
Returns:
  • A KubernetesJob object.

trigger

Create a Kubernetes job and return a KubernetesJobRun object.