Skip to content
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

feat: add k8s client wrapper and constants #201

Merged
merged 21 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ and the taskmaster ends, completing the task.
need either an FTP account or a PVC that can be accessed from within or from
outside of the cluster by the workflow manager (more in the
[deployment](deployment/documentation/deployment.md) page).

### Environment Variables

| **Environment Variable** | **Default Value** | **Description** |
|-------------------------------------------------|----------------------------------------------------|------------------------------------------------|
| `TESK_API_TASKMASTER_FILER_IMAGE_NAME` | `docker.io/elixircloud/tesk-core-filer` | Name of the filer image |
| `TESK_API_TASKMASTER_FILER_IMAGE_VERSION` | `latest` | Version of the filer image |
| `TESK_API_TASKMASTER_IMAGE_NAME` | `docker.io/elixircloud/tesk-core-taskmaster` | Name of the taskmaster image |
| `TESK_API_TASKMASTER_IMAGE_VERSION` | `latest` | Version of the taskmaster image |
| `TESK_API_K8S_NAMESPACE` | `tesk` | Namespace in which TESK creates K8s resources |
| `TESK_API_TASKMASTER_SERVICE_ACCOUNT_NAME` | `taskmaster` | Taskmaster service account name |
| `ENVIRONMENT_EXECUTOR_BACKOFF_LIMIT` | `6` | Backoff limit for taskmaster execution |
| `FILER_BACKOFF_LIMIT` | `2` | Backoff limit for filer job |
| `EXECUTOR_BACKOFF_LIMIT` | `2` | Backoff limit for executor job |
18 changes: 18 additions & 0 deletions docs/source/pages/tesk/tesk.api.ga4gh.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tesk.api.ga4gh package
======================

Subpackages
-----------

.. toctree::
:maxdepth: 4

tesk.api.ga4gh.tes

Module contents
---------------

.. automodule:: tesk.api.ga4gh
:members:
:undoc-members:
:show-inheritance:
37 changes: 37 additions & 0 deletions docs/source/pages/tesk/tesk.api.ga4gh.tes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
tesk.api.ga4gh.tes package
==========================

Subpackages
-----------

.. toctree::
:maxdepth: 4

tesk.api.ga4gh.tes.service_info

Submodules
----------

tesk.api.ga4gh.tes.controllers module
-------------------------------------

.. automodule:: tesk.api.ga4gh.tes.controllers
:members:
:undoc-members:
:show-inheritance:

tesk.api.ga4gh.tes.models module
--------------------------------

.. automodule:: tesk.api.ga4gh.tes.models
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: tesk.api.ga4gh.tes
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/source/pages/tesk/tesk.api.ga4gh.tes.service_info.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
tesk.api.ga4gh.tes.service\_info package
========================================

Submodules
----------

tesk.api.ga4gh.tes.service\_info.service\_info module
-----------------------------------------------------

.. automodule:: tesk.api.ga4gh.tes.service_info.service_info
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: tesk.api.ga4gh.tes.service_info
:members:
:undoc-members:
:show-inheritance:
18 changes: 18 additions & 0 deletions docs/source/pages/tesk/tesk.api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tesk.api package
================

Subpackages
-----------

.. toctree::
:maxdepth: 4

tesk.api.ga4gh

Module contents
---------------

.. automodule:: tesk.api
:members:
:undoc-members:
:show-inheritance:
29 changes: 29 additions & 0 deletions docs/source/pages/tesk/tesk.k8s.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
tesk.k8s package
================

Submodules
----------

tesk.k8s.constants module
-------------------------

.. automodule:: tesk.k8s.constants
:members:
:undoc-members:
:show-inheritance:

tesk.k8s.wrapper module
-----------------------

.. automodule:: tesk.k8s.wrapper
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: tesk.k8s
:members:
:undoc-members:
:show-inheritance:
45 changes: 45 additions & 0 deletions docs/source/pages/tesk/tesk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,53 @@ Subpackages
.. toctree::
:maxdepth: 4

tesk.api
tesk.k8s
tesk.services

Submodules
----------

tesk.app module
---------------

.. automodule:: tesk.app
:members:
:undoc-members:
:show-inheritance:

tesk.constants module
---------------------

.. automodule:: tesk.constants
:members:
:undoc-members:
:show-inheritance:

tesk.custom\_config module
--------------------------

.. automodule:: tesk.custom_config
:members:
:undoc-members:
:show-inheritance:

tesk.exceptions module
----------------------

.. automodule:: tesk.exceptions
:members:
:undoc-members:
:show-inheritance:

tesk.utils module
-----------------

.. automodule:: tesk.utils
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

Expand Down
2,142 changes: 1,118 additions & 1,024 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ boto3 = "1.34.104"
foca = "^0.13.0"
kubernetes = "^29.0.0"
python = "^3.11"
requests = ">=2.20.0"
werkzeug = "==2.2.3" # Remove when FOCA updates this dependency.
urllib3 = "^2.2.2"

[tool.poetry.group.docs.dependencies]
Expand Down
78 changes: 78 additions & 0 deletions tesk/constants.py
JaeAeich marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Tesk scoped constants."""

import os

from pydantic import BaseModel


class TeskConstants(BaseModel):
"""Tesk's K8s scoped constants.

Attributes:
FILER_IMAGE_NAME: Name of the filer image
FILER_IMAGE_VERSION: Version of the filer image
TASKMASTER_IMAGE_NAME: Name of the taskmaster image
TASKMASTER_IMAGE_VERSION: Version of the taskmaster image
TESK_NAMESPACE: Namespace in which api will create K8s resources from TES
request
TASKMASTER_SERVICE_ACCOUNT_NAME: Taskmaster service account name
TASKMASTER_ENVIRONMENT_EXECUTOR_BACKOFF_LIMIT: Backoff limit for taskmaster env
FILER_BACKOFF_LIMIT: Backoff limit got filer job
EXECUTOR_BACKOFF_LIMIT: Backoff limit for executor job

Note:
Below are the mentioned environment variable with which these constants can be
configured, otherwise mentioned default will be assigned.

variable:
ENV_VARIABLE = default

FILER_IMAGE_NAME:
TESK_API_TASKMASTER_FILER_IMAGE_NAME = docker.io/elixircloud/tesk-core-filer
FILER_IMAGE_VERSION:
TESK_API_TASKMASTER_FILER_IMAGE_VERSION = latest
TASKMASTER_IMAGE_NAME:
TESK_API_TASKMASTER_IMAGE_NAME = docker.io/elixircloud/tesk-core-taskmaster
TASKMASTER_IMAGE_VERSION:
TESK_API_TASKMASTER_IMAGE_VERSION = latest
TESK_NAMESPACE:
TESK_API_K8S_NAMESPACE = tesk
TASKMASTER_SERVICE_ACCOUNT_NAME:
TESK_API_TASKMASTER_SERVICE_ACCOUNT_NAME = taskmaster
TASKMASTER_ENVIRONMENT_EXECUTOR_BACKOFF_LIMIT:
ENVIRONMENT_EXECUTOR_BACKOFF_LIMIT = 6
FILER_BACKOFF_LIMIT:
FILER_BACKOFF_LIMIT = 2
EXECUTOR_BACKOFF_LIMIT:
EXECUTOR_BACKOFF_LIMIT = 2
"""

FILER_IMAGE_NAME: str = os.getenv(
"TESK_API_TASKMASTER_FILER_IMAGE_NAME", "docker.io/elixircloud/tesk-core-filer"
)
FILER_IMAGE_VERSION: str = os.getenv(
"TESK_API_TASKMASTER_FILER_IMAGE_VERSION", "latest"
)
TASKMASTER_IMAGE_NAME: str = os.getenv(
"TESK_API_TASKMASTER_IMAGE_NAME", "docker.io/elixircloud/tesk-core-taskmaster"
)
TASKMASTER_IMAGE_VERSION: str = os.getenv(
"TESK_API_TASKMASTER_IMAGE_VERSION", "latest"
)
TESK_NAMESPACE: str = os.getenv("TESK_API_K8S_NAMESPACE", "tesk")
TASKMASTER_SERVICE_ACCOUNT_NAME: str = os.getenv(
"TESK_API_TASKMASTER_SERVICE_ACCOUNT_NAME", "taskmaster"
)
TASKMASTER_ENVIRONMENT_EXECUTOR_BACKOFF_LIMIT: str = os.getenv(
"ENVIRONMENT_EXECUTOR_BACKOFF_LIMIT", "6"
)
FILER_BACKOFF_LIMIT: str = os.getenv("FILER_BACKOFF_LIMIT", "2")
EXECUTOR_BACKOFF_LIMIT: str = os.getenv("EXECUTOR_BACKOFF_LIMIT", "2")

class Config:
"""Configuration for class."""

frozen = True


tesk_constants = TeskConstants()
5 changes: 5 additions & 0 deletions tesk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
OAuthProblem,
Unauthorized,
)
from kubernetes.client.exceptions import ApiException
from werkzeug.exceptions import (
BadRequest,
InternalServerError,
Expand All @@ -18,6 +19,10 @@ class ConfigNotFoundError(FileNotFoundError):
"""Configuration file not found error."""


class KubernetesError(ApiException):
"""Kubernetes error."""


# exceptions raised in app context
exceptions = {
Exception: {
Expand Down
1 change: 1 addition & 0 deletions tesk/k8s/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Kubernetes API module for TESK."""
Loading
Loading