Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add internal endpoints for sessions and expose backend #2083

Merged
merged 1 commit into from
Dec 13, 2024
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
10 changes: 10 additions & 0 deletions backend/capellacollab/configuration/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ class K8sConfig(BaseConfig):
description="The name of the IngressClass to use.",
examples=["traefik", "nginx"],
)
management_portal_namespace: str = pydantic.Field(
default="collab-manager",
description="The namespace where the management portal is deployed in.",
examples=["collab-manager"],
)
release_name: str = pydantic.Field(
default="dev",
description="The release name of the Helm chart",
examples=["dev", "prod", "test123"],
)


class GeneralConfig(BaseConfig):
Expand Down
8 changes: 8 additions & 0 deletions backend/capellacollab/sessions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SessionEnvironment(t.TypedDict):
CAPELLACOLLAB_SESSION_TOKEN: str
CAPELLACOLLAB_SESSION_ID: str
CAPELLACOLLAB_SESSION_REQUESTER_USERNAME: str
CAPELLACOLLAB_SESSION_REQUESTER_USER_ID: int
CAPELLACOLLAB_SESSION_CONNECTION_METHOD_TYPE: str
CAPELLACOLLAB_SESSION_CONTAINER_PORT: str

Expand All @@ -51,6 +52,7 @@ class SessionEnvironment(t.TypedDict):
CAPELLACOLLAB_SESSIONS_BASE_PATH: str

CAPELLACOLLAB_ORIGIN_BASE_URL: str
CAPELLACOLLAB_API_BASE_URL: str


class SessionProvisioningRequest(core_pydantic.BaseModel):
Expand Down Expand Up @@ -131,6 +133,12 @@ class Session(core_pydantic.BaseModel):
connection_method_id: str
connection_method: tools_models.ToolSessionConnectionMethod | None = None

@pydantic.computed_field # type: ignore[misc]
@property
def internal_endpoint(self) -> str:
"""Internal DNS endpoint of the session for inter-session communication."""
return f"{self.id}.{config.k8s.namespace}.svc.cluster.local"

shared_with: list[SessionSharing] = pydantic.Field(default=[])

project: projects_models.SimpleProject | None = pydantic.Field(
Expand Down
2 changes: 2 additions & 0 deletions backend/capellacollab/sessions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ def get_environment(
),
"CAPELLACOLLAB_SESSION_ID": session_id,
"CAPELLACOLLAB_SESSION_REQUESTER_USERNAME": user.name,
"CAPELLACOLLAB_SESSION_REQUESTER_USER_ID": user.id,
"CAPELLACOLLAB_SESSIONS_BASE_PATH": f"/session/{session_id}",
"CAPELLACOLLAB_SESSION_CONNECTION_METHOD_TYPE": connection_method.type,
"CAPELLACOLLAB_ORIGIN_BASE_URL": f"{config.general.scheme}://{config.general.host}:{config.general.port}",
"CAPELLACOLLAB_SESSIONS_SCHEME": config.general.scheme,
"CAPELLACOLLAB_SESSIONS_HOST": config.general.host,
"CAPELLACOLLAB_SESSIONS_PORT": str(config.general.port),
"CAPELLACOLLAB_SESSION_CONTAINER_PORT": str(container_port),
"CAPELLACOLLAB_API_BASE_URL": f"http://{config.k8s.release_name}-backend.{config.k8s.management_portal_namespace}.svc.cluster.local/api",
}


Expand Down
12 changes: 12 additions & 0 deletions docs/docs/admin/tools/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ variables can be used by the tool:
<td>`janedoe`</td>
<td>The username of the user who has requested the session.</td>
</tr>
<tr>
<td>`CAPELLACOLLAB_SESSION_REQUESTER_USER_ID`</td>
<td>`123`</td>
<td>The ID of the user who has requested the session.</td>
</tr>
<tr>
<td>`CAPELLACOLLAB_SESSION_CONTAINER_PORT`</td>
<td>`8080`</td>
Expand Down Expand Up @@ -167,6 +172,13 @@ variables can be used by the tool:
The tool has to set the `Content-Security-Policy` header to `frame-ancestors self {CAPELLACOLLAB_ORIGIN_HOST}`. Otherwise, the session viewer can't be used with the tool!
</td>
</tr>
<tr>
<td>`CAPELLACOLLAB_API_BASE_URL`</td>
<td>`http://dev-backend.collab-manager.svc.cluster.local:/api`</td>
<td>
The API URL of the Collaboration Manager. The URL is only available from the session itself.
</td>
</tr>
<tr>
<td>`WORKSPACE_DIR`</td>
<td>`/workspace`</td>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/openapi/model/session.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/src/storybook/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const mockPersistentSession: Readonly<Session> = {
state: SessionState.Running,
owner: mockUser,
connection_method: { ...mockHttpConnectionMethod, name: 'Xpra' },
internal_endpoint:
'vfurvsrldxfwwsqdiqvnufonh.collab-sessions.svc.cluster.local',
warnings: [],
connection_method_id: 'default',
shared_with: [],
Expand Down
3 changes: 3 additions & 0 deletions helm/config/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ docker:

k8s:
namespace: {{ .Values.backend.k8sSessionNamespace }}
managementPortalNamespace: {{ .Release.Namespace }}
releaseName: {{ .Release.Name }}

{{- if .Values.cluster.namespaces.sessions.ingressClassName }}
ingressClassName: {{ .Values.cluster.namespaces.sessions.ingressClassName }}
{{- end }}
Expand Down
19 changes: 19 additions & 0 deletions helm/templates/backend/backend.networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-from-{{- .Values.backend.k8sSessionNamespace -}}-to-backend
namespace: {{ .Release.Namespace }}
spec:
podSelector:
matchLabels:
id: {{ .Release.Name }}-deployment-backend
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ .Values.backend.k8sSessionNamespace }}
policyTypes:
- Ingress
Loading