Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion operator/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,22 @@ def build_environment(

DM_PROJECT_DIR is mandatory (the app exits without it); the remaining DM_*
variables provide instance metadata.

When an instance id is known we also set DM_BASE_PATH to '/<instance-id>'.
The viz-app uses this to serve under the Ingress sub-path (its assets,
client-side routes and API calls are then resolved relative to the prefix);
without it the app would serve from '/' and render a blank page behind the
path-based Ingress. It is omitted when no instance id is available.
"""
return [
env: List[Dict[str, str]] = [
{"name": "DM_PROJECT_DIR", "value": project_mount_path},
{"name": "DM_PROJECT_ID", "value": str(project_id)},
{"name": "DM_INSTANCE_ID", "value": str(instance_id)},
{"name": "DM_INSTANCE_OWNER", "value": str(instance_owner)},
]
if instance_id:
env.append({"name": "DM_BASE_PATH", "value": f"/{instance_id}"})
return env


def build_deployment_body(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ def test_build_environment_exposes_dm_metadata() -> None:
assert by_name["DM_INSTANCE_OWNER"] == "dlister"


def test_build_environment_sets_dm_base_path_from_instance_id() -> None:
# The viz-app serves under a sub-path when DM_BASE_PATH is set; the operator
# mirrors the instance id (prefixed with '/') so assets, client-side routes
# and API calls resolve under the Ingress prefix.
env = _example_environment()
by_name = {item["name"]: item["value"] for item in env}
assert by_name["DM_BASE_PATH"] == "/instance-111"


def test_build_environment_omits_dm_base_path_when_instance_id_absent() -> None:
# Without an instance id there is no sub-path; the app then serves at '/'.
env = handlers.build_environment(
project_id="project-000",
instance_id="",
instance_owner="dlister",
project_mount_path=PROJECT_MOUNT_PATH,
)
by_name = {item["name"]: item["value"] for item in env}
assert "DM_BASE_PATH" not in by_name


# --- service ----------------------------------------------------------------


Expand Down
Loading