diff --git a/gateway/models.py b/gateway/models.py index f33965c..9960093 100644 --- a/gateway/models.py +++ b/gateway/models.py @@ -12,6 +12,7 @@ class HealthCheck(BaseModel): status: str = "OK" +# General class User(BaseModel): """Example User output""" @@ -36,13 +37,6 @@ class AuthConfiguration(BaseModel): issuer_url: str -class KeycloakConfig(BaseModel): - """Keycloak configuration.""" - realm: str - url: str - clientId: str - - class GatewayFormData(FormData): """Specialized form model with methods for parsing field data as well as uploaded files.""" @@ -114,3 +108,24 @@ async def upload(self, key, value: UploadFile | str): elif isinstance(value, str): # If simply a string, then add to form self.add_www_form(name=key, value=value) + + +# Metadata models +class KeycloakConfig(BaseModel): + """Keycloak configuration.""" + realm: str + url: str + clientId: str + + +class ContainerInfo(BaseModel): + """Formatted container information.""" + id: int + name: str + job_id: int + image: str + state: str + status: str + next_tag: str + repo: str + train_class_id: int diff --git a/gateway/routers/k8s.py b/gateway/routers/k8s.py index 673e8fa..88872dd 100644 --- a/gateway/routers/k8s.py +++ b/gateway/routers/k8s.py @@ -6,6 +6,7 @@ from gateway.auth import oauth2_scheme from gateway.conf import gateway_settings +from gateway.models import ContainerInfo k8s_router = APIRouter( dependencies=[Security(oauth2_scheme)], @@ -52,3 +53,12 @@ async def get_k8s_svc_by_namespace(namespace: Annotated[str, Path(title="Namespa # TODO improve output and limit requested information # https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md return k8s_api.list_namespaced_service(namespace=namespace).to_dict() + + +@k8s_router.get("/images", response_model=list[ContainerInfo]) +async def get_k8s_images(): + """Get a list of k8s images.""" + k8s_api = initialize_k8s_api_conn() + # https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md + # Add field selector: https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/ + return k8s_api.list_namespaced_pod().to_dict() diff --git a/gateway/routers/metadata.py b/gateway/routers/metadata.py index 11c2431..52689e0 100644 --- a/gateway/routers/metadata.py +++ b/gateway/routers/metadata.py @@ -1,4 +1,4 @@ -"""EPs for various metata for the frontend.""" +"""EPs for various metadata for the frontend.""" from fastapi import APIRouter @@ -25,4 +25,4 @@ async def get_keycloak_config(): @metadata_router.get("/metadata/version") async def get_node_version(): """Return version of the node software/API.""" - return "0.1.0-version" + return {"appVersion": "0.1.0-gatewayapi"} diff --git a/gateway/server.py b/gateway/server.py index e4ea5b4..46faf23 100644 --- a/gateway/server.py +++ b/gateway/server.py @@ -73,4 +73,4 @@ def get_health() -> HealthCheck: ) if __name__ == "__main__": - uvicorn.run("server:app", host="127.0.0.1", port=8081) + uvicorn.run("server:app", host="127.0.0.1", port=8081, reload=True)