-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
899 additions
and
677 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Empty file.
This file contains 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
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""A container for a single Kubernetes job object (can be both a taskmaster and an executor) and its list of worker pods (Kubernetes Pod objects).""" | ||
|
||
from typing import List, Optional | ||
|
||
from kubernetes.client import V1Job, V1Pod | ||
|
||
|
||
class Job: | ||
"""A container for a single Kubernetes job object (can be both a taskmaster and an executor) and its list of worker pods (Kubernetes Pod objects)""" | ||
|
||
def __init__(self, job: V1Job): | ||
"""Initializes the Job with a Kubernetes job object.""" | ||
self.job: V1Job = job | ||
self.pods: List[V1Pod] = [] | ||
|
||
def get_job(self) -> V1Job: | ||
"""Returns the Kubernetes job object.""" | ||
return self.job | ||
|
||
def add_pod(self, pod: V1Pod): | ||
"""Adds a single pod to the list (without any duplication checks).""" | ||
# TODO: This doesn't take care of duplication, use set on id or name | ||
self.pods.append(pod) | ||
|
||
def has_pods(self) -> bool: | ||
"""Checks if the job has any pods.""" | ||
return bool(self.pods) | ||
|
||
def get_first_pod(self) -> Optional[V1Pod]: | ||
"""Returns arbitrarily chosen pod from the list (currently the first one added) or None if the job has no pods.""" | ||
if not self.has_pods(): | ||
return None | ||
return self.pods[0] | ||
|
||
def get_pods(self) -> List[V1Pod]: | ||
"""Returns the list of job pods in the order of addition to the list or an empty list if no pods.""" | ||
return self.pods | ||
|
||
def change_job_name(self, new_name: str): | ||
"""Changes the job name, as well as the names in its metadata and container specs.""" | ||
self.job.metadata.name = new_name | ||
self.job.spec.template.metadata.name = new_name | ||
if self.job.spec.template.spec.containers: | ||
self.job.spec.template.spec.containers[0].name = new_name | ||
|
||
def get_job_name(self) -> Optional[str]: | ||
"""Returns the job name.""" | ||
return self.job.metadata.name |
Oops, something went wrong.