-
Notifications
You must be signed in to change notification settings - Fork 31
feat: create TES task as k8s job #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JaeAeich
wants to merge
23
commits into
main
Choose a base branch
from
createTask
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6a578b0
feat: create task
JaeAeich 4edd278
chore: update poetry lock
JaeAeich 009ca53
review
JaeAeich 84dfc46
merge
JaeAeich 2429b0f
WIP
JaeAeich cebb7b2
create task
JaeAeich eb652f4
make ruff happy
JaeAeich 89e2dfb
make typos happy
JaeAeich f9b630b
make mypy happy
JaeAeich 5f44926
make bandit happy
JaeAeich ad17a00
fix config
JaeAeich 2b7a251
minor
JaeAeich da720a7
chore: WIP list task
JaeAeich 38f2b46
chore: clean up a bit
JaeAeich 0cd3110
fix error
JaeAeich aaad8fb
fix: add fixed image and add image to containers
JaeAeich 46bbe2a
fix: missing commands
JaeAeich 099c528
fix: missing name of exec
JaeAeich d96b6ae
fix: update the image
JaeAeich d545d24
fix minor
JaeAeich 9d1b89c
change image for taskmaster
lvarin e2adc6f
fix: When restartPolicy or resouces.limits are missing
lvarin 104aa05
fix: Code is using tabs, instead of 4 spaces
lvarin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| """Task API controller logic.""" |
This file contains hidden or 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,77 @@ | ||
| """TESK API module for creating a task.""" | ||
|
|
||
| import logging | ||
|
|
||
| from tesk.api.ga4gh.tes.models import TesTask | ||
| from tesk.api.kubernetes.client_wrapper import KubernetesClientWrapper | ||
| from tesk.api.kubernetes.constants import Constants | ||
| from tesk.api.kubernetes.converter import TesKubernetesConverter | ||
| from tesk.exceptions import KubernetesError | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class CreateTesTask: | ||
| """Create TES task.""" | ||
|
|
||
| def __init__(self, task: TesTask, user=None, namespace="default"): | ||
|
JaeAeich marked this conversation as resolved.
Outdated
|
||
| """Initialize the CreateTask class. | ||
|
|
||
| Args: | ||
| task: TES task to create. | ||
| user: User who creates the task. | ||
| namespace: Kubernetes namespace where the task is created. | ||
| """ | ||
| self.task = task | ||
| self.user = user | ||
| self.kubernetes_client_wrapper = KubernetesClientWrapper() | ||
| self.namespace = namespace | ||
| self.tes_kubernetes_converter = TesKubernetesConverter(self.namespace) | ||
| self.constants = Constants() | ||
|
|
||
| def create_task(self): | ||
| """Create TES task.""" | ||
| attempts_no = 0 | ||
| while True: | ||
|
JaeAeich marked this conversation as resolved.
Outdated
|
||
| try: | ||
| resources = self.task.resources | ||
|
|
||
| if resources and resources.ram_gb: | ||
| minimum_ram_gb = self.kubernetes_client_wrapper.minimum_ram_gb() | ||
| if resources.ram_gb < minimum_ram_gb: | ||
| self.task.resources.ram_gb = minimum_ram_gb | ||
|
|
||
| task_master_job = ( | ||
| self.tes_kubernetes_converter.from_tes_task_to_k8s_job( | ||
| self.task, self.user | ||
| ) | ||
| ) | ||
|
|
||
| # TODO: Create ConfigMap | ||
| # TODO: Create Job | ||
| # TODO Return created job | ||
| # task_master_config_map = converter.from_tes_task_to_k8s_config_map( | ||
| # task, user, task_master_job | ||
| # ) | ||
| # created_config_map = kubernetes_client_wrapper.create_config_map( | ||
| # task_master_config_map | ||
| # ) | ||
| # created_job = kubernetes_client_wrapper.create_job(task_master_job) | ||
| # return converter.from_k8s_job_to_tes_create_task_response(created_job) | ||
|
|
||
| except KubernetesError as e: | ||
| # Handle Kubernetes specific exceptions | ||
| if ( | ||
| not e.is_object_name_duplicated() | ||
| or attempts_no >= self.constants.job_create_attempts_no | ||
| ): | ||
| raise e | ||
| attempts_no += 1 | ||
|
|
||
| except Exception as exc: | ||
| logging.error("ERROR: In createTask", exc_info=True) | ||
| raise exc | ||
|
|
||
| def response(self) -> dict: | ||
| """Create response.""" | ||
| return self.create_task() | ||
This file contains hidden or 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 @@ | ||
| """Kubernetes API module.""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.