Skip to content

Commit

Permalink
feat: add support for starting ssh enabled sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Grubenmann committed Jan 25, 2023
1 parent bf591d0 commit 46ef889
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
disk_request: 1G
gpu_request: 0
lfs_auto_fetch: false
ssh_request: false
serverOptions:
cpu_request:
order: 1
Expand Down
2 changes: 2 additions & 0 deletions helm-chart/renku-notebooks/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ spec:
value: {{ .Values.sessionAutosave.terminationGracePeriodSeconds | quote }}
- name: NB_SESSIONS__AUTOSAVE_MINIMUM_LFS_FILE_SIZE_BYTES
value: {{ .Values.sessionAutosave.minimumLFSFileSizeBytes | quote }}
- name: NB_SESSION_SSH__ENABLED
value: {{ .Values.session_ssh.enabled | quote }}
- name: NB_VERSION
value: {{ .Values.image.tag | quote }}
{{ if .Values.sessionsNamespace }}
Expand Down
9 changes: 6 additions & 3 deletions helm-chart/renku-notebooks/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,17 @@
"mem_request": { "$ref": "#/definitions/informationAmount" },
"lfs_auto_fetch": { "type": "boolean" },
"gpu_request": { "$ref": "#/definitions/gpuRequest" },
"disk_request": { "$ref": "#/definitions/informationAmountOrNull" }
"disk_request": { "$ref": "#/definitions/informationAmountOrNull" },
"ssh_request": { "type": "boolean" }
},
"required": [
"defaultUrl",
"cpu_request",
"mem_request",
"lfs_auto_fetch",
"gpu_request",
"disk_request"
"disk_request",
"ssh_request"
],
"type": "object",
"additionalProperties": false
Expand All @@ -254,7 +256,8 @@
"mem_request": { "$ref": "#/definitions/serverOptionMemory" },
"lfs_auto_fetch": { "$ref": "#/definitions/serverOptionBool" },
"gpu_request": { "$ref": "#/definitions/serverOptionGpu" },
"disk_request": { "$ref": "#/definitions/serverOptionDisk" }
"disk_request": { "$ref": "#/definitions/serverOptionDisk" },
"ssh_request": { "$ref": "#/definitions/serverOptionBool" }
},
"required": [
"lfs_auto_fetch"
Expand Down
11 changes: 10 additions & 1 deletion helm-chart/renku-notebooks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ global:
clientSecret:
keycloak:
## The name of the realm in Keycloak used by Renku
realm:
realm:

amalthea:
scope:
Expand Down Expand Up @@ -65,6 +65,9 @@ cloudstorage:
enabled: false
readOnly: true

session_ssh:
enabled: false

# configuration for user session persistent volumes
userSessionPersistentVolumes:
enabled: true
Expand Down Expand Up @@ -215,6 +218,11 @@ serverOptions:
displayName: Automatically fetch LFS data
type: boolean
default: false
ssh_request:
order: 6
displayName: Enable SSH connections
type: boolean
default: false

## Default server option values used to launch a session when
## such values are not provided explicitly in the post request.
Expand All @@ -229,6 +237,7 @@ serverDefaults:
disk_request: 1G
gpu_request: 0
lfs_auto_fetch: false
ssh_request: false

## How to enforce CPU limits for sessions, options are "lax", "off" or "strict"
## - "strict" = CPU limit equals cpu request
Expand Down
8 changes: 8 additions & 0 deletions renku_notebooks/api/amalthea_patches/jupyter_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def env(server: "UserServer"):
"path": "/statefulset/spec/template/spec/containers/0/env/-",
"value": {"name": "GIT_CLONE_REPO", "value": "true"},
},
{
"op": "add",
"path": "/statefulset/spec/template/spec/containers/0/env/-",
"value": {
"name": "RENKU_ENABLE_SSH",
"value": "1" if server.server_options.get("ssh_request") else "0",
},
},
]

if server.environment_variables:
Expand Down
11 changes: 11 additions & 0 deletions renku_notebooks/api/classes/server_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ def server_options(self) -> Dict[str, Any]:
for env in patch.get("value", {}).get("env", []):
if env.get("name") == "GIT_CLONE_LFS_AUTO_FETCH":
server_options["lfs_auto_fetch"] = env.get("value") == "1"
# ssh request
if config.sessions.session_ssh_enabled:
for patches in js["spec"]["patches"]:
for patch in patches.get("patch", []):
if (
patch.get("path")
== "/statefulset/spec/template/spec/containers/0/env/-"
):
for env in patch.get("value", {}).get("env", []):
if env.get("name") == "RENKU_ENABLE_SSH":
server_options["ssh_request"] = env.get("value") == "1"
return {
**config.server_options.defaults,
**server_options,
Expand Down
2 changes: 2 additions & 0 deletions renku_notebooks/api/schemas/config_server_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ServerOptionsChoices(Schema):
disk_request = fields.Nested(MemoryServerOptionsChoice, required=False)
lfs_auto_fetch = fields.Nested(BoolServerOptionsChoice, required=False)
gpu_request = fields.Nested(GpuServerOptionsChoice, required=False)
ssh_request = fields.Nested(BoolServerOptionsChoice, required=False)


class ServerOptionsDefaults(Schema):
Expand All @@ -95,6 +96,7 @@ class ServerOptionsDefaults(Schema):
disk_request = ByteSizeField(required=True)
lfs_auto_fetch = fields.Bool(required=True)
gpu_request = GpuField(required=True)
ssh_request = fields.Bool(required=True)


class CloudStorageServerOption(Schema):
Expand Down
3 changes: 3 additions & 0 deletions renku_notebooks/api/schemas/server_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ class LaunchNotebookRequestServerOptions(Schema):
config.server_options.defaults,
),
)
ssh_request = fields.Bool(
required=False, missing=config.server_options.defaults["ssh_request"]
)
1 change: 1 addition & 0 deletions renku_notebooks/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def get_config(default_config: str) -> _NotebooksConfig:
}
enforce_cpu_limits: false
autosave_minimum_lfs_file_size_bytes: 1000000
session_ssh_enabled: false
termination_grace_period_seconds: 600
image_default_workdir: /home/jovyan
node_selector: "{}"
Expand Down
1 change: 1 addition & 0 deletions renku_notebooks/config/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class _SessionConfig:
default_image: Text = "renku/singleuser:latest"
enforce_cpu_limits: Union[Text, bool] = False
autosave_minimum_lfs_file_size_bytes: Union[int, Text] = 1000000
session_ssh_enabled: Union[Text, bool] = False
termination_grace_period_seconds: Union[int, Text] = 600
image_default_workdir: Text = "/home/jovyan"
node_selector: Text = "{}"
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/dummy_server_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@
"min": "1G",
"max": "100G"
}
},
"ssh_request": {
"default": false,
"displayName": "Enable SSH connections",
"order": 6,
"type": "boolean"
}
}
1 change: 1 addition & 0 deletions tests/unit/test_server_class/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_session_manifest(
"cpu_request": "100",
"mem_request": "100",
"disk_request": "100",
"ssh_request": 0,
},
"branch": "master",
"commit_sha": "abcdefg123456789",
Expand Down

0 comments on commit 46ef889

Please sign in to comment.