Skip to content

Commit

Permalink
add toleration method
Browse files Browse the repository at this point in the history
  • Loading branch information
marekliszka committed Apr 3, 2023
1 parent 3398bec commit 9685db1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion kubeluigi/__init__.py
Expand Up @@ -16,6 +16,7 @@

from kubernetes.client import ApiClient
from kubernetes.client.models.v1_job import V1Job
from kubernetes.client import V1Toleration
from kubernetes.client.models.v1_pod_spec import V1PodSpec

logger = logging.getLogger(__name__)
Expand All @@ -24,6 +25,7 @@
class KubernetesJobTask:

volumes: List[AttachableVolume] = []
tolerations: List[V1Toleration]

def _init_task_metadata(self):
self.uu_name = self.name
Expand Down Expand Up @@ -79,7 +81,7 @@ def build_job_definition(self) -> V1Job:
schema = self.spec_schema()
schema_with_volumes = self._attach_volumes_to_spec(schema)
pod_template_spec = pod_spec_from_dict(
self.uu_name, schema_with_volumes, self.labels, self.restart_policy
self.uu_name, schema_with_volumes, self.labels, self.restart_policy, tolerations=self.tolerations
)

job = job_definition(
Expand Down Expand Up @@ -147,3 +149,7 @@ def add_volume(self, volume):
adds a volume to the task
"""
return self.volumes.append(volume)

def add_toleration(self, key, value, effect='NoSchedule', operator='Equals'):
toleration = V1Toleration(key=key, value=value, effect=effect, operator=operator)
return self.tolerations.append(toleration)

0 comments on commit 9685db1

Please sign in to comment.