Skip to content

Commit

Permalink
feat(metadata): begin adding EPs for frontend metadata collection
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Mar 6, 2024
1 parent 4abc611 commit 5c2674f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
29 changes: 22 additions & 7 deletions gateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class HealthCheck(BaseModel):
status: str = "OK"


# General
class User(BaseModel):
"""Example User output"""

Expand All @@ -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."""

Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions gateway/routers/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down Expand Up @@ -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()
4 changes: 2 additions & 2 deletions gateway/routers/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""EPs for various metata for the frontend."""
"""EPs for various metadata for the frontend."""

from fastapi import APIRouter

Expand All @@ -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"}
2 changes: 1 addition & 1 deletion gateway/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5c2674f

Please sign in to comment.