File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
src/etos_api/routers/logs Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616"""ETOS API log handler."""
17+ import os
1718import asyncio
1819import logging
1920from uuid import UUID
2425from starlette .requests import Request
2526import httpx
2627
28+ NAMESPACE_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
2729LOGGER = logging .getLogger (__name__ )
2830ROUTER = APIRouter ()
2931
3638 LOGGER .warning ("Could not load a Kubernetes config" )
3739
3840
41+ def namespace () -> str :
42+ """Get current namespace if available."""
43+ if not os .path .isfile (NAMESPACE_FILE ):
44+ LOGGER .warning (
45+ "Not running in Kubernetes. Cannot figure out namespace. "
46+ "Defaulting to environment variable 'ETOS_NAMESPACE'."
47+ )
48+ return os .getenv ("ETOS_NAMESPACE" )
49+ with open (NAMESPACE_FILE , encoding = "utf-8" ) as namespace_file :
50+ return namespace_file .read ()
51+
52+
3953@ROUTER .get ("/logs/{uuid}" , tags = ["logs" ])
4054async def get_logs (uuid : UUID , request : Request ):
4155 """Get logs from an ETOS pod and stream them back as server sent events."""
4256 corev1 = client .CoreV1Api ()
43- thread = corev1 .list_namespaced_pod ("etos-development" , async_req = True )
57+ thread = corev1 .list_namespaced_pod (namespace () , async_req = True )
4458 pod_list = thread .get ()
4559
4660 ip_addr = None
You can’t perform that action at this time.
0 commit comments