Skip to content

Commit 28225c1

Browse files
sgaistolevski
andcommitted
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 fa68e17 commit 28225c1

File tree

27 files changed

+654
-89
lines changed

27 files changed

+654
-89
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
@@ -151,21 +151,15 @@ help: ## Display this help.
151151

152152
##@ Helm/k8s
153153

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

164158
install_amaltheas: ## Installs both version of amalthea in the. NOTE: It uses the currently active k8s context.
165159
helm repo add renku https://swissdatasciencecenter.github.io/helm-charts
166160
helm repo update
167161
helm upgrade --install amalthea-js renku/amalthea --version $(AMALTHEA_JS_VERSION)
168-
helm upgrade --install amalthea-sessions amalthea-sessions-0.0.9-new-operator-chart.tgz --version $(AMALTHEA_SESSIONS_VERSION)
162+
helm upgrade --install amalthea-se renku/amalthea-sessions --version ${AMALTHEA_SESSIONS_VERSION}
169163

170164
# TODO: Add the version variables from the top of the file here when the charts are fully published
171165
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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,8 @@ components:
454454
message:
455455
type: string
456456
example: "Something went wrong - please try again later"
457-
required:
458-
- "code"
459-
- "message"
460-
required:
461-
- "error"
457+
required: ["code", "message"]
458+
required: ["error"]
462459
Generated:
463460
properties:
464461
enabled:
@@ -881,7 +878,7 @@ components:
881878
type: integer
882879
description: The size of disk storage for the session, in gigabytes
883880
resource_class_id:
884-
default:
881+
default:
885882
nullable: true
886883
type: integer
887884
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)