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

Update to work with the ETOS controller #106

Merged
merged 34 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
83b9dfb
Make environment provider compatible with the kubernetes controller
t-persson Jul 25, 2024
3a13559
Kubernetes from etos library
t-persson Jul 26, 2024
0a4278c
Get providers from testrun instead
t-persson Jul 26, 2024
e41974e
Delete environment when testrun deletes
t-persson Jul 26, 2024
910d0b0
Handle dataset
t-persson Jul 26, 2024
094b03b
Fix a bug with providers
t-persson Jul 26, 2024
7c5487a
Update to the expected new versions
t-persson Jul 30, 2024
ce5bab1
Get testrun name from environment instead of guessing
t-persson Aug 1, 2024
614c713
Utilize the TestRunSchema and load TERCC from environment or k8s
t-persson Aug 2, 2024
3271c68
Fix release_all
t-persson Aug 12, 2024
650d14b
Add an entrypoint
t-persson Aug 12, 2024
f38c836
Raise exception when failing
t-persson Aug 13, 2024
a299b95
Get environment ID from environment variables
t-persson Aug 13, 2024
64a5fce
Wait for ESR activity
t-persson Aug 14, 2024
9da7d3b
Use the REQUEST_ID as context
t-persson Aug 14, 2024
25dc848
Update environment provider to mostly use EnvironmentRequest
t-persson Aug 15, 2024
922627e
Add environment request as owner to environment
t-persson Aug 15, 2024
4d9d1b9
Clean up config
t-persson Aug 19, 2024
ac30371
Remove debug code
t-persson Aug 19, 2024
88e4a0f
Add dockerfile
t-persson Aug 19, 2024
7164082
Clean up release code
t-persson Aug 22, 2024
8950b43
Fix a few review comments
t-persson Aug 26, 2024
09696c8
Add result to termination log
t-persson Aug 27, 2024
ee93dbe
Add more debug prints
t-persson Aug 27, 2024
d2faff4
Set ETOS RabbitMQ parameters
t-persson Aug 28, 2024
7988532
Remove duplication
t-persson Oct 10, 2024
04581a3
Fix the code so that tox does not complain
t-persson Oct 16, 2024
6a8bf8b
Make clear when to use the Dockerfile
t-persson Oct 16, 2024
0a7da20
Check for python version before using a new feature
t-persson Oct 16, 2024
fa4d801
Go back in time to an earlier python version
t-persson Oct 16, 2024
84a7239
Update ETOS library version
t-persson Oct 22, 2024
7419109
Fix the tests by mocking out Kubernetes
t-persson Oct 22, 2024
b6babc9
Review comment fixes
t-persson Nov 21, 2024
190213a
Fix import of opentelemetry.trace
t-persson Nov 21, 2024
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
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dockerfile to use with the controller environment where we run the environment provider as a Job
# instead of running it as an imported service in the suite runner.
FROM python:3.9-bookworm AS build

COPY . /src
WORKDIR /src
RUN pip install --no-cache-dir build && python3 -m build

FROM python:3.9-slim-bookworm

COPY --from=build /src/dist/*.whl /tmp
# hadolint ignore=DL3013

RUN pip install --no-cache-dir /tmp/*.whl && groupadd -r etos && useradd -r -m -s /bin/false -g etos etos

USER etos

LABEL org.opencontainers.image.source=https://github.com/eiffel-community/etos-environment-provider
LABEL org.opencontainers.image.authors=etos-maintainers@googlegroups.com
LABEL org.opencontainers.image.licenses=Apache-2.0

CMD ["python", "-u", "-m", "environment_provider.environment_provider"]
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"jsontas~=1.3",
"packageurl-python~=0.11",
"etcd3gw~=2.3",
"etos_lib==4.3.6",
"etos-lib==4.4.1",
"opentelemetry-api~=1.21",
"opentelemetry-exporter-otlp~=1.21",
"opentelemetry-sdk~=1.21",
Expand Down Expand Up @@ -52,4 +52,4 @@ norecursedirs = ["dist", "build", ".tox"]
testpaths = ["tests"]

[tool.setuptools.packages]
find = { where = ["src"], exclude = ["tests"] }
find = { where = ["src"], exclude = ["tests"] }
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cryptography>=42.0.4,<43.0.0
jsontas~=1.3
packageurl-python~=0.11
etcd3gw~=2.3
etos_lib==4.3.6
etos-lib==4.4.1
opentelemetry-api~=1.21
opentelemetry-exporter-otlp~=1.21
opentelemetry-sdk~=1.21
Expand Down
39 changes: 32 additions & 7 deletions src/environment_provider/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"""Backend for the environment requests."""
import json
import time
import sys
import traceback
import logging
import re
from typing import Optional, Union

Expand All @@ -26,6 +28,7 @@

from environment_provider.lib.database import ETCDPath
from environment_provider.lib.registry import ProviderRegistry
from environment_provider.lib.releaser import EnvironmentReleaser
from execution_space_provider import ExecutionSpaceProvider
from execution_space_provider.execution_space import ExecutionSpace
from iut_provider import IutProvider
Expand Down Expand Up @@ -71,16 +74,12 @@ def release_environment(
"""
etos.config.set("SUITE_ID", sub_suite.get("suite_id"))
iut = sub_suite.get("iut")
iut_ruleset = provider_registry.get_iut_provider_by_id(iut.get("provider_id")).get("iut")
iut_ruleset = provider_registry.get_iut_provider().get("iut")
executor = sub_suite.get("executor")
executor_ruleset = provider_registry.get_execution_space_provider_by_id(
executor.get("provider_id")
).get("execution_space")
executor_ruleset = provider_registry.get_execution_space_provider().get("execution_space")

log_area = sub_suite.get("log_area")
log_area_ruleset = provider_registry.get_log_area_provider_by_id(
log_area.get("provider_id")
).get("log")
log_area_ruleset = provider_registry.get_log_area_provider().get("log")

failure = None

Expand Down Expand Up @@ -151,3 +150,29 @@ def release_full_environment(etos: ETOS, jsontas: JsonTas, suite_id: str) -> tup
traceback.format_exception(failure, value=failure, tb=failure.__traceback__)
)
return True, ""


def run(environment_id: str):
"""Run is an entrypoint for releasing environments."""
logformat = "[%(asctime)s] %(levelname)s:%(message)s"
logging.basicConfig(
level=logging.INFO, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S"
)
try:
releaser = EnvironmentReleaser()
releaser.run(environment_id)
result = {"conclusion": "Successful", "description": "Successfully released an environment"}
with open("/dev/termination-log", "w", encoding="utf-8") as termination_log:
json.dump(result, termination_log)
except:
try:
result = {"conclusion": "Failed", "description": traceback.format_exc()}
with open("/dev/termination-log", "w", encoding="utf-8") as termination_log:
json.dump(result, termination_log)
except PermissionError:
pass
raise


if __name__ == "__main__":
run(sys.argv[1])
fredjn marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading