Skip to content

Conversation

@JaeAeich
Copy link

@JaeAeich JaeAeich commented Sep 5, 2024

Summary by Sourcery

Add functionality to create TES tasks and convert them into Kubernetes jobs, including new modules and API endpoints. Refactor existing code for consistency and enhance error handling.

New Features:

  • Introduce a new feature to create TES tasks and convert them into Kubernetes jobs, including handling of taskmaster and executor jobs.
  • Add a new module for converting TES tasks to Kubernetes jobs, including handling of taskmaster and executor jobs.
  • Implement a new API endpoint for creating tasks in the TESK API, which processes task requests and returns responses.

Enhancements:

  • Refactor the existing code to use lowercase constants for better consistency and readability.
  • Enhance the KubernetesError class to include a method for checking if an object name is duplicated.

@JaeAeich JaeAeich requested a review from lvarin September 5, 2024 18:15
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 5, 2024

Reviewer's Guide by Sourcery

This pull request implements the creation of a task in the TESK (TES on Kubernetes) system. It introduces new modules for converting TES tasks to Kubernetes jobs, handling task creation requests, and managing the execution of tasks. The changes primarily focus on the backend implementation of task creation, including the conversion of TES task specifications to Kubernetes job configurations.

File-Level Changes

Change Details Files
Implement TES task to Kubernetes job conversion
  • Create TesKubernetesConverter class for converting TES tasks to Kubernetes jobs
  • Implement methods to convert TES executors to Kubernetes jobs
  • Add utility methods for generating Kubernetes job and config map templates
tesk/k8s/converter/converter.py
tesk/k8s/converter/template.py
Implement task creation API endpoint
  • Create CreateTask function in the API controller
  • Implement CreateTesTask class for handling task creation requests
  • Add error handling and retry logic for task creation
tesk/api/ga4gh/tes/controllers.py
tesk/api/ga4gh/tes/task/create_task.py
Add data structures for managing Kubernetes resources
  • Create Job class to represent Kubernetes job objects
  • Implement Task class to manage the relationship between taskmaster and executor jobs
  • Add utility methods for manipulating job and task objects
tesk/k8s/converter/data/job.py
tesk/k8s/converter/data/task.py
Update utility functions and constants
  • Modify get_taskmaster_template function to include new configuration options
  • Update constants and configuration structures
  • Add new utility functions for handling Pydantic models and Kubernetes resources
tesk/utils.py
tesk/exceptions.py
tesk/api/ga4gh/tes/models.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @JaeAeich - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding more unit tests for the new converter and task creation logic to ensure robustness and catch potential edge cases.
  • The error handling in CreateTesTask is good, but consider adding more detailed logging throughout the conversion process to aid in debugging and monitoring.
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@JaeAeich JaeAeich requested a review from jemaltahir September 6, 2024 12:06
@JaeAeich JaeAeich requested a review from uniqueg September 6, 2024 12:14
Copy link

@jemaltahir jemaltahir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments from PR 206, can be revisited here as well. All in all great work :)

Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't yet managed to review the converter subpackage. Let's see that we get #206 merged and all of the other comments addressed first as things are becoming too complex to review effectively.

@JaeAeich JaeAeich requested a review from uniqueg October 8, 2024 16:03
Base automatically changed from template to main October 13, 2024 17:09
@codecov
Copy link

codecov bot commented Oct 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.21%. Comparing base (a3e2cc2) to head (5607e62).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #207   +/-   ##
=======================================
  Coverage   98.21%   98.21%           
=======================================
  Files           8        8           
  Lines         561      561           
=======================================
  Hits          551      551           
  Misses         10       10           
Flag Coverage Δ
test_unit 98.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to leave it off here for now - it's very late. I'll try my best to go through this, but note that it is 2000 lines or so of complex code. It will take several more hours to go through this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that second part is where I would see this going then. Maybe even ending up in FOCA.

I mean, if we already have 21 changed files (not including tests) for the addition of a single controller, we might as well go all the way, right? 😛

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JaeAeich: Why is it that with your PRs I often see the entire file changed, even though it's just an iteration over the last time I've viewed? I don't have this with other people, so I guess it's something with your editor or Git flow.

Please have a look at this, because it's really quite annoying. Instead of just focusing on what changed since the last time, I have to look through the entire file again - which is not only not fun, but also holds up the reviews big time, especially when they tend to end up being huge.

And even apart from that, it's also really not good practice in terms of provenance. If this were previously existing code (e.g., maybe some of the old TES code from TES-core still remains), you'd end up being listed as git blame for every line, taking credit and blame for other people's work.

@uniqueg
Copy link
Member

uniqueg commented Oct 14, 2024

Please also note that some checks are failing and unit tests for the code are entirely missing as of yet. I suppose you can already go ahead addressing/adding these while I finalize the review (it's obviously mostly good code, so I wouldn't expect that a lot of the tests will need to be rewritten).

Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor open issues to fix

import json
import os
from pathlib import Path
from typing import List, Sequence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Py 3.9 onwards, you can use list, dict etc. - no need to import the capitalized version from typing (but you still need to import Sequence). And I hope we're not using Py 3.8 or lower, since they are beyond end of life.

batch_api: Kubernetes batch API client
core_api: Kubernetes core API client
namespace: Kubernetes namespace
tesk_k8s_constant: TESK Kubernetes constants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be consistent with the naming. It's multiple constants, so please name it constants throughout, as arg and as attribute, in the code and in the docs.

Comment on lines +33 to +37
try:
res: dict = json.loads(json.dumps(response))
return res
except (TypeError, ValueError) as e:
logger.info(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the error? Do you think it's a bug in Pydantic? If you really have good reason to use this code as it is, I think you should document inside the code exactly why you couldn't just validate the model with Pydantic, and do so by linking to an existing issue.

Currently my assumption is that there's something wrong with your code and this workaround just masks that.

self.tesk_k8s_constants = tesk_k8s_constants

@abstractmethod
def handle_request(self) -> BaseModel:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a more specific model that is returned? I mean the function is called handle_request(), not handle_model().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I meant that it happens between reviews. If I have seen and checked a file in review #1, it shouldn't be entirely green again in review #2, unless the entire file changed between reviews #1 and #2 - which shouldn't really happen.

Anyway... please rename it somehow. If it's generic to a degree that at some point we might put it in FOCA (which it certainly isn't in its current form), maybe just use request.py and Request for module and class, respectively? Otherwise maybe tes_request.py and TesRequest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants