Skip to content

Commit

Permalink
Allow the environment provider to be used when not in Kubernetes (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-persson authored Nov 22, 2024
1 parent 9b543a8 commit 0a85f46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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.4.1",
"etos-lib==4.4.2",
"opentelemetry-api~=1.21",
"opentelemetry-exporter-otlp~=1.21",
"opentelemetry-sdk~=1.21",
Expand Down
16 changes: 13 additions & 3 deletions src/environment_provider/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
from typing import Optional

from urllib3.exceptions import MaxRetryError
from etos_lib import ETOS
from etos_lib.kubernetes.schemas.testrun import Suite
from etos_lib.kubernetes.schemas.environment_request import (
Expand Down Expand Up @@ -59,9 +60,18 @@ def __init__(self, etos: ETOS, kubernetes: Kubernetes, ids: Optional[list[str]]
@property
def etos_controller(self) -> bool:
"""Whether or not the environment provider is running as a part of the ETOS controller."""
request = EnvironmentRequest(self.kubernetes)
request_name = os.getenv("REQUEST")
return request_name is not None and request.exists(request_name)
try:
request = EnvironmentRequest(self.kubernetes)
request_name = os.getenv("REQUEST")
return request_name is not None and request.exists(request_name)
except MaxRetryError:
self.logger.warning(
"Could not initialize EnvironmentRequest client, "
"assuming that the environment provider is not running "
"in Kubernetes or that the ETOS controller system is not "
"deployed in this cluster."
)
return False

def load_config(self) -> None:
"""Load config from environment variables."""
Expand Down

0 comments on commit 0a85f46

Please sign in to comment.