Skip to content

Commit

Permalink
Merge pull request #9 from pminervini/main
Browse files Browse the repository at this point in the history
Let users specify the namespace where to run a job
  • Loading branch information
AntreasAntoniou authored Dec 13, 2023
2 parents bb40d90 + 7f96198 commit 35469b7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kubejobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class KubernetesJob:
secret_env_vars (dict, optional): Dictionary of secret environment variables. Defaults to None.
env_vars (dict, optional): Dictionary of normal (non-secret) environment variables. Defaults to None.
volume_mounts (dict, optional): Dictionary of volume mounts. Defaults to None.
namespace (str, optional): Namespace of the job. Defaults to None.
Methods:
generate_yaml() -> dict: Generate the Kubernetes Job YAML configuration.
Expand Down Expand Up @@ -115,6 +116,7 @@ def __init__(
user_email: Optional[str] = None,
labels: Optional[dict] = None,
annotations: Optional[dict] = None,
namespace: Optional[str] = None
):
self.name = name

Expand Down Expand Up @@ -176,6 +178,8 @@ def __init__(
logger.info(f"labels {self.labels}")
logger.info(f"annotations {self.annotations}")

self.namespace = namespace

def _add_shm_size(self, container: dict):
"""Adds shared memory volume if shm_size is set."""
if self.shm_size:
Expand Down Expand Up @@ -319,6 +323,9 @@ def generate_yaml(self):
if self.job_deadlineseconds:
job["spec"]["activeDeadlineSeconds"] = self.job_deadlineseconds

if self.namespace:
job["metadata"]["namespace"] = self.namespace

if not (
self.gpu_type is None
or self.gpu_limit is None
Expand Down

0 comments on commit 35469b7

Please sign in to comment.