Skip to content

Commit

Permalink
Handle issues with ordering and missing resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Aug 14, 2024
1 parent c4dd8d2 commit 94ee55b
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 98 deletions.
3 changes: 3 additions & 0 deletions lookup-service/service/caches/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class WorkshopEnvironment:

portal: "TrainingPortal"
name: str
uid: str
generation: int
workshop: str
title: str
Expand All @@ -37,6 +38,7 @@ def __init__(
self,
portal: "TrainingPortal",
name: str,
uid: str,
generation: int,
workshop: str,
title: str,
Expand All @@ -50,6 +52,7 @@ def __init__(
) -> None:
self.portal = portal
self.name = name
self.uid = uid
self.generation = generation
self.workshop = workshop
self.title = title
Expand Down
274 changes: 179 additions & 95 deletions lookup-service/service/handlers/clusters.py

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions lookup-service/service/routes/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,42 @@ async def api_get_v1_clusters_portals(request: web.Request) -> web.Response:
return web.json_response(data)


@login_required
@roles_accepted("admin")
async def api_get_v1_clusters_portals_details(request: web.Request) -> web.Response:
"""Returns details for the specified portal running on a cluster."""

cluster_name = request.match_info["cluster"]
portal_name = request.match_info["portal"]

service_state = request.app["service_state"]
cluster_database = service_state.cluster_database

cluster = cluster_database.get_cluster(cluster_name)

if not cluster:
return web.Response(text="Cluster not available", status=403)

portal = cluster.get_portal(portal_name)

if not portal:
return web.Response(text="Portal not available", status=403)

details = {
"name": portal.name,
"uid": portal.uid,
"generation": portal.generation,
"labels": portal.labels,
"cluster": portal.cluster.name,
"url": portal.url,
"capacity": portal.capacity,
"allocated": portal.allocated,
"phase": portal.phase,
}

return web.json_response(details)


@login_required
@roles_accepted("admin")
async def api_get_v1_clusters_portals_environments(
Expand Down Expand Up @@ -131,6 +167,7 @@ async def api_get_v1_clusters_portals_environments(
"environments": [
{
"name": environment.name,
"uid": environment.uid,
"generation": environment.generation,
"workshop": environment.workshop,
"title": environment.title,
Expand Down Expand Up @@ -182,6 +219,7 @@ async def api_get_v1_clusters_portals_environments_details(

details = {
"name": environment.name,
"uid": environment.uid,
"generation": environment.generation,
"workshop": environment.workshop,
"title": environment.title,
Expand Down Expand Up @@ -350,6 +388,10 @@ async def api_get_v1_clusters_portals_environments_users_sessions(
web.get("/api/v1/clusters/{cluster}", api_get_v1_clusters_details),
web.get("/api/v1/clusters/{cluster}/kubeconfig", api_get_v1_clusters_kubeconfig),
web.get("/api/v1/clusters/{cluster}/portals", api_get_v1_clusters_portals),
web.get(
"/api/v1/clusters/{cluster}/portals/{portal}",
api_get_v1_clusters_portals_details,
),
web.get(
"/api/v1/clusters/{cluster}/portals/{portal}/environments",
api_get_v1_clusters_portals_environments,
Expand Down
17 changes: 17 additions & 0 deletions session-manager/handlers/trainingportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
# Calculate name for the portal namespace.

portal_name = name
portal_uid = uid

portal_namespace = f"{portal_name}-ui"

# Calculate access details for the portal. The hostname used to access the
Expand Down Expand Up @@ -388,6 +390,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
f"training.{OPERATOR_API_GROUP}/policy.engine": CLUSTER_SECURITY_POLICY_ENGINE,
f"training.{OPERATOR_API_GROUP}/policy.name": "baseline",
},
Expand Down Expand Up @@ -444,6 +447,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"roleRef": {
Expand Down Expand Up @@ -472,6 +476,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"roleRef": {
Expand Down Expand Up @@ -530,6 +535,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
}
Expand All @@ -544,6 +550,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"type": "kubernetes.io/service-account-token",
Expand All @@ -557,6 +564,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"roleRef": {
Expand Down Expand Up @@ -584,6 +592,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"spec": {
Expand All @@ -604,6 +613,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"data": {
Expand All @@ -620,6 +630,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
f"training.{OPERATOR_API_GROUP}/portal.services.dashboard": "true",
},
},
Expand All @@ -633,6 +644,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"deployment": "training-portal",
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
f"training.{OPERATOR_API_GROUP}/portal.services.dashboard": "true",
},
},
Expand Down Expand Up @@ -850,6 +862,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"spec": {
Expand All @@ -868,6 +881,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
"annotations": {},
},
Expand Down Expand Up @@ -936,6 +950,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"spec": {
Expand Down Expand Up @@ -969,6 +984,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"spec": {
Expand Down Expand Up @@ -997,6 +1013,7 @@ def training_portal_create(name, uid, body, spec, status, patch, runtime, retry,
"labels": {
f"training.{OPERATOR_API_GROUP}/component": "portal",
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
},
},
"spec": {
Expand Down
10 changes: 10 additions & 0 deletions session-manager/handlers/workshopallocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,16 @@ def workshop_allocation_create(
portal_name = meta.get("labels", {}).get(
f"training.{OPERATOR_API_GROUP}/portal.name", ""
)
portal_uid = meta.get("labels", {}).get(
f"training.{OPERATOR_API_GROUP}/portal.uid", ""
)

environment_name = spec["environment"]["name"]

environment_uid = meta.get("labels", {}).get(
f"training.{OPERATOR_API_GROUP}/environment.uid", ""
)

workshop_namespace = environment_name

session_name = spec["session"]["name"]
Expand Down Expand Up @@ -448,7 +456,9 @@ def workshop_allocation_create(
f"training.{OPERATOR_API_GROUP}/component.group": "objects",
f"training.{OPERATOR_API_GROUP}/workshop.name": workshop_name,
f"training.{OPERATOR_API_GROUP}/portal.name": portal_name,
f"training.{OPERATOR_API_GROUP}/portal.uid": portal_uid,
f"training.{OPERATOR_API_GROUP}/environment.name": environment_name,
f"training.{OPERATOR_API_GROUP}/environment.uid": environment_uid,
f"training.{OPERATOR_API_GROUP}/session.name": session_name,
f"training.{OPERATOR_API_GROUP}/session.objects": "true",
}
Expand Down
Loading

0 comments on commit 94ee55b

Please sign in to comment.