Skip to content

Commit 30923b5

Browse files
sgaistolevski
andauthored
feat: ensure notebook endpoints do their job (#388)
This work brings the notebook related endpoints to a working state to serve as replacement for the renku-notebooks external service. Short summary: - API tests have been added - Code has been fixed to answer / handle exception - Automated test cluster creation has been added using k3d --------- Co-authored-by: Tasko Olevski <[email protected]>
1 parent 8878712 commit 30923b5

File tree

30 files changed

+666
-101
lines changed

30 files changed

+666
-101
lines changed

.devcontainer/.poetry_cache/.keep

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"command": "poetry self add poetry-polylith-plugin"
1212
},
1313
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
14-
"ghcr.io/mpriscella/features/kind:1": {},
1514
"ghcr.io/devcontainers-contrib/features/gh-release:1": {
1615
"repo": "authzed/zed",
1716
"binaryNames": "zed"
@@ -28,7 +27,8 @@
2827
"ghcr.io/EliiseS/devcontainer-features/bash-profile:1": {
2928
"command": "alias k=kubectl"
3029
},
31-
"ghcr.io/devcontainers-contrib/features/rclone:1": {}
30+
"ghcr.io/devcontainers-contrib/features/rclone:1": {},
31+
"./k3d": {}
3232
},
3333
"overrideFeatureInstallOrder": [
3434
"ghcr.io/devcontainers-contrib/features/poetry",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "k3d",
3+
"version": "1.0.0",
4+
"name": "k3s based kubernetes cluster in docker",
5+
"postCreateCommand": "k3d --version",
6+
"installsAfter": [
7+
"ghcr.io/devcontainers-contrib/features/bash-command"
8+
],
9+
"options": {
10+
"k3d_version": {
11+
"type": "string",
12+
"description": "k3d version to install",
13+
"proposals": ["latest", "5.7.4"],
14+
"default": "latest"
15+
}
16+
}
17+
}

.devcontainer/k3d/install.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if [ "${K3D_VERSION}" != "none" ]; then
2+
echo "Downloading k3d..."
3+
if [ "${K3D_VERSION}" = "latest" ]; then
4+
# Install and check the hash
5+
curl -sSL https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
6+
else
7+
find_version_from_git_tags K3D_VERSION https://github.com/kubernetes/K3D
8+
if [ "${K3D_VERSION::1}" != "v" ]; then
9+
K3D_VERSION="v${K3D_VERSION}"
10+
fi
11+
# Install and check the hash
12+
curl -sSL https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG="${K3D_VERSION}" bash
13+
fi
14+
fi

.github/workflows/test_publish.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ jobs:
9595
- uses: actions/checkout@v4
9696
with:
9797
fetch-depth: 0
98+
- uses: actions/cache/restore@v3
99+
name: Restore cache
100+
with:
101+
path: ${{ env.CACHE_PATH }}
102+
key: ${{ env.CACHE_KEY }}
98103
- name: Set Git config
99104
shell: bash
100105
run: |

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ repos:
1818
- id: check-toml
1919
- id: debug-statements
2020
- id: end-of-file-fixer
21+
exclude: 'components/renku_data_services/message_queue/(avro_models|schemas)'
2122
- id: mixed-line-ending
2223
- id: trailing-whitespace
24+
exclude: 'components/renku_data_services/message_queue/(avro_models|schemas)'
2325
- repo: https://github.com/asottile/yesqa
2426
rev: v1.5.0
2527
hooks:

Makefile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.PHONY: schemas tests test_setup main_tests schemathesis_tests collect_coverage style_checks pre_commit_checks run download_avro check_avro avro_models update_avro kind_cluster install_amaltheas all
1+
.PHONY: schemas tests test_setup main_tests schemathesis_tests collect_coverage style_checks pre_commit_checks run download_avro check_avro avro_models update_avro k3d_cluster install_amaltheas all
22

33
AMALTHEA_JS_VERSION ?= 0.12.2
4-
AMALTHEA_SESSIONS_VERSION ?= 0.0.9-new-operator-chart
4+
AMALTHEA_SESSIONS_VERSION ?= 0.0.10-new-operator-chart
55
codegen_params = --input-file-type openapi --output-model-type pydantic_v2.BaseModel --use-double-quotes --target-python-version 3.12 --collapse-root-models --field-constraints --strict-nullable --set-default-enum-member --openapi-scopes schemas paths parameters --set-default-enum-member --use-one-literal-as-default --use-default
66

77
define test_apispec_up_to_date
@@ -143,21 +143,15 @@ help: ## Display this help.
143143

144144
##@ Helm/k8s
145145

146-
kind_cluster: ## Creates a kind cluster for testing
147-
kind delete cluster
148-
docker network rm -f kind
149-
docker network create -d=bridge -o com.docker.network.bridge.enable_ip_masquerade=true -o com.docker.network.driver.mtu=1500 --ipv6=false kind
150-
kind create cluster --config kind_config.yaml
151-
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
152-
echo "Waiting for ingress controller to initialize"
153-
sleep 15
154-
kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s
146+
k3d_cluster: ## Creates a k3d cluster for testing
147+
k3d cluster delete
148+
k3d cluster create --agents 1 --k3s-arg --disable=metrics-server@server:0
155149

156150
install_amaltheas: ## Installs both version of amalthea in the. NOTE: It uses the currently active k8s context.
157151
helm repo add renku https://swissdatasciencecenter.github.io/helm-charts
158152
helm repo update
159153
helm upgrade --install amalthea-js renku/amalthea --version $(AMALTHEA_JS_VERSION)
160-
helm upgrade --install amalthea-sessions amalthea-sessions-0.0.9-new-operator-chart.tgz --version $(AMALTHEA_SESSIONS_VERSION)
154+
helm upgrade --install amalthea-se renku/amalthea-sessions --version ${AMALTHEA_SESSIONS_VERSION}
161155

162156
# TODO: Add the version variables from the top of the file here when the charts are fully published
163157
amalthea_schema: ## Updates generates pydantic classes from CRDs

components/renku_data_services/base_api/auth.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,30 @@ async def decorated_function(*args: _P.args, **kwargs: _P.kwargs) -> _T:
180180
return response
181181

182182
return decorated_function
183+
184+
185+
def internal_gitlab_authenticate(
186+
authenticator: Authenticator,
187+
) -> Callable[
188+
[Callable[Concatenate[Request, APIUser, APIUser, _P], Coroutine[Any, Any, _T]]],
189+
Callable[Concatenate[Request, APIUser, _P], Coroutine[Any, Any, _T]],
190+
]:
191+
"""Decorator for a Sanic handler that that adds a user for the internal gitlab user."""
192+
193+
def decorator(
194+
f: Callable[Concatenate[Request, APIUser, APIUser, _P], Coroutine[Any, Any, _T]],
195+
) -> Callable[Concatenate[Request, APIUser, _P], Coroutine[Any, Any, _T]]:
196+
@wraps(f)
197+
async def decorated_function(
198+
request: Request,
199+
user: APIUser,
200+
*args: _P.args,
201+
**kwargs: _P.kwargs,
202+
) -> _T:
203+
access_token = str(request.headers.get("Gitlab-Access-Token"))
204+
internal_gitlab_user = await authenticator.authenticate(access_token, request)
205+
return await f(request, user, internal_gitlab_user, *args, **kwargs)
206+
207+
return decorated_function
208+
209+
return decorator

components/renku_data_services/notebooks/api.spec.yaml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,8 @@ components:
455455
message:
456456
type: string
457457
example: "Something went wrong - please try again later"
458-
required:
459-
- "code"
460-
- "message"
461-
required:
462-
- "error"
458+
required: ["code", "message"]
459+
required: ["error"]
463460
Generated:
464461
properties:
465462
enabled:
@@ -478,7 +475,7 @@ components:
478475
repositories:
479476
type: array
480477
default: []
481-
items:
478+
items:
482479
"$ref": "#/components/schemas/LaunchNotebookRequestRepository"
483480
cloudstorage:
484481
default: []
@@ -489,7 +486,7 @@ components:
489486
default: 1
490487
type: integer
491488
resource_class_id:
492-
default:
489+
default:
493490
nullable: true
494491
type: integer
495492
environment_variables:
@@ -539,7 +536,7 @@ components:
539536
default: {}
540537
type: object
541538
image:
542-
default:
539+
default:
543540
nullable: true
544541
type: string
545542
lfs_auto_fetch:
@@ -548,13 +545,13 @@ components:
548545
namespace:
549546
type: string
550547
notebook:
551-
default:
548+
default:
552549
nullable: true
553550
type: string
554551
project:
555552
type: string
556553
resource_class_id:
557-
default:
554+
default:
558555
nullable: true
559556
type: integer
560557
serverOptions:
@@ -565,7 +562,7 @@ components:
565562
user_secrets:
566563
allOf:
567564
- "$ref": "#/components/schemas/UserSecrets"
568-
default:
565+
default:
569566
nullable: true
570567
required:
571568
- commit_sha
@@ -660,7 +657,7 @@ components:
660657
properties:
661658
configuration:
662659
additionalProperties: {}
663-
default:
660+
default:
664661
nullable: true
665662
type: object
666663
readonly:
@@ -669,7 +666,7 @@ components:
669666
source_path:
670667
type: string
671668
storage_id:
672-
default:
669+
default:
673670
nullable: true
674671
type: string
675672
target_path:
@@ -882,7 +879,7 @@ components:
882879
type: integer
883880
description: The size of disk storage for the session, in gigabytes
884881
resource_class_id:
885-
default:
882+
default:
886883
nullable: true
887884
type: integer
888885
cloudstorage:

components/renku_data_services/notebooks/api/amalthea_patches/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def session_tolerations(server: "UserServer") -> list[dict[str, Any]]:
3030
"op": "add",
3131
"path": "/statefulset/spec/template/spec/tolerations",
3232
"value": default_tolerations
33-
+ [i.json_match_expression() for i in server.server_options.tolerations],
33+
+ [toleration.json_match_expression() for toleration in server.server_options.tolerations],
3434
}
3535
],
3636
}

0 commit comments

Comments
 (0)