Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Update grader setup service environment variables #560

Merged
merged 3 commits into from
Apr 28, 2021
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
22 changes: 21 additions & 1 deletion src/graderservice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,31 @@ Install in editable mode:
Run application locally with debug mode enabled:

```bash
export FLASK_APP=src/graderservice/graderservice
export FLASK_APP=graderservice
export FLASK_ENV=development
flask run
```

> **Note**: the service does require environment variables however all have defaults. You can set your own values by using the `export <env-var-here>=<env-var-value>` before starting the application. You can also set environment variables with the docker run command.

## Update Dependencies

pip-compile requirements.in

## Environment Variables

| Environment Variable | Description | Type | Default Value |
| --- | --- | --- | --- |
| GRADER_IMAGE_NAME | The shared grader notebook image:tag | `string` | `illumidesk/grader-notebook:latest` |
| GRADER_PVC | The Kubernetes PVC for the grader setup service | `string` | `grader-setup-pvc` |
| GRADER_SHARED_PVC | The shared grader notebook PVC for the exchange directory | `string` | `exchange-shared-volume` |
| ILLUMIDESK_MNT_ROOT | Root directory for `{org_name}/grader-{course_id}` | `string` | `/illumidesk-courses` |
| ILLUMIDESK_NB_EXCHANGE_MNT_ROOT | Root directory for `{org_name}/exchange` | `string` | `/illumidesk-nb-exchange` |
| IS_DEBUG | Sets the debug option to True or False for the Kubernetes client and the shared grader notebook | `bool` | `True` |
| NAMESPACE | The Kubernetes namespace name | `string` | `default` |
| NB_UID | The user's uid that owns the shared grader home directory | `integer` | `10001` |
| NB_GID | The user's gid that owns the shared grader home directory | `integer` | `100` |

## License

Apache 2.0
22 changes: 14 additions & 8 deletions src/graderservice/graderservice/graderservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
)

# user UI and GID to use within the grader container
NB_UID = 10001
NB_GID = 100
NB_UID = os.environ.get("NB_UID", 10001)
NB_GID = os.environ.get("NB_GID", 100)

# NBGrader DATABASE settings to save in nbgrader_config.py file
nbgrader_db_host = os.environ.get("POSTGRES_NBGRADER_HOST")
Expand All @@ -50,13 +50,15 @@


class GraderServiceLauncher:
def __init__(self, org_name: str, course_id: str):
def __init__(self, org_name: str, course_id: str, is_debug: bool = False):
"""
Helper class to launch grader notebooks within the kubernetes cluster

Args:
org_name: the organization name
course_id: the course id
is_debug: if true, runs the grader notebook and the kubernetes client with
debugging enabled. Defaults to False.

Raises:
ConfigException if the kubectl python client does not have a valid configuration set.
Expand All @@ -69,15 +71,18 @@ def __init__(self, org_name: str, course_id: str):
# next method uses the KUBECONFIG env var by default
config.load_kube_config()
# Uncomment the following lines to enable debug logging
c = client.Configuration()
c.debug = True
apps_v1 = client.AppsV1Api(api_client=client.ApiClient(configuration=c))
self.apps_v1 = client.AppsV1Api()
kube_client_config = client.Configuration()
kube_client_config.debug = is_debug
self.apps_v1 = client.AppsV1Api(
api_client=client.ApiClient(configuration=kube_client_config)
)
self.coreV1Api = client.CoreV1Api()
self.course_id = course_id
self.org_name = org_name
self.grader_is_debug = is_debug
self.grader_name = f"grader-{self.course_id}"
self.grader_token = token_hex(32)
self.org_name = org_name

# Course home directory, its parent should be the grader name
self.course_dir = Path(
f"{MNT_ROOT}/{self.org_name}/home/grader-{self.course_id}/{self.course_id}"
Expand Down Expand Up @@ -233,6 +238,7 @@ def _create_deployment_object(self):
),
security_context=client.V1SecurityContext(allow_privilege_escalation=False),
env=[
client.V1EnvVar(name="DEBUG", value=self.grader_is_debug),
client.V1EnvVar(name="JUPYTERHUB_SERVICE_NAME", value=self.course_id),
client.V1EnvVar(name="JUPYTERHUB_API_TOKEN", value=self.grader_token),
# we're using the K8s Service name 'hub' (defined in the jhub helm chart)
Expand Down
12 changes: 8 additions & 4 deletions src/graderservice/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ def grader_setup_environ(monkeypatch):
"""
Set the enviroment variables used in Course class
"""
monkeypatch.setenv("NAMESPACE", "default")
monkeypatch.setenv("ILLUMIDESK_K8S_NAMESPACE", "default")
monkeypatch.setenv("ILLUMIDESK_MNT_ROOT", "/illumidesk-courses")
monkeypatch.setenv("ILLUMIDESK_NB_EXCHANGE_MNT_ROOT", "/illumidesk-nb-exchange")
monkeypatch.setenv("GRADER_EXCHANGE_SHARED_PVC", "exchange-shared-volume")
monkeypatch.setenv("GRADER_IMAGE_NAME", "illumidesk/grader-notebook:latest")
monkeypatch.setenv("MNT_ROOT", "/illumidesk-courses")
monkeypatch.setenv("EXCHANGE_MNT_ROOT", "/illumidesk-nb-exchange")
monkeypatch.setenv("GRADER_PVC", "grader-setup-pvc")
monkeypatch.setenv("GRADER_EXCHANGE_SHARED_PVC", "exchange-shared-volume")
monkeypatch.setenv("GRADER_SHARED_PVC", "exchange-shared-volume")
monkeypatch.setenv("IS_DEBUG", "True")
monkeypatch.setenv("MNT_ROOT", "/illumidesk-courses")
monkeypatch.setenv("NAMESPACE", "default")
monkeypatch.setenv("NB_UID", "10001")
monkeypatch.setenv("NB_GID", "100")