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(ws): refactor backend models and repositories #192

Merged

Conversation

thesuperzapper
Copy link
Member

closes: #127
closes: #128

What does this PR do?

This PR significantly refactors the Notebooks 2.0 backend API:

  1. Factors out the models and repositories into sub-folders for each of healthcheck, namespaces, workspaces, and workspacekinds.
  2. Slightly changes the API response formats (see below for sample responses).
  3. Fixes the case when a Workspace uses a WorkspaceKind that does not exist:
    • We now just populate any unknown fields with default values like __UNKNOWN_POD_CONFIG__ and __UNKNOWN_IMAGE_CONFIG__.
  4. Updates a lot of tests.

Sample API Responses

List WorkspaceKinds

curl -i localhost:4000/api/v1/workspacekinds

{
    "data": [
        {
            "name": "jupyterlab",
            "display_name": "JupyterLab Notebook",
            "description": "A Workspace which runs JupyterLab in a Pod",
            "deprecated": false,
            "deprecation_message": "This WorkspaceKind will be removed on 20XX-XX-XX, please use another WorkspaceKind.",
            "hidden": false,
            "icon": {
                "url": "/workspaces/backend/api/v1/workspacekinds/jupyterlab/assets/icon"
            },
            "logo": {
                "url": "/workspaces/backend/api/v1/workspacekinds/jupyterlab/assets/logo"
            },
            "pod_template": {
                "pod_metadata": {
                    "labels": {
                        "my-workspace-kind-label": "my-value"
                    },
                    "annotations": {
                        "my-workspace-kind-annotation": "my-value"
                    }
                },
                "volume_mounts": {
                    "home": "/home/jovyan"
                },
                "options": {
                    "image_config": {
                        "default": "jupyterlab_scipy_190",
                        "values": [
                            {
                                "id": "jupyterlab_scipy_180",
                                "displayName": "jupyter-scipy:v1.8.0",
                                "description": "JupyterLab, with SciPy Packages",
                                "labels": [
                                    {
                                        "key": "python_version",
                                        "value": "3.11"
                                    }
                                ],
                                "hidden": true,
                                "redirect": {
                                    "to": "jupyterlab_scipy_190",
                                    "message": {
                                        "text": "This update will change...",
                                        "level": "Info"
                                    }
                                }
                            },
                            {
                                "id": "jupyterlab_scipy_190",
                                "displayName": "jupyter-scipy:v1.9.0",
                                "description": "JupyterLab, with SciPy Packages",
                                "labels": [
                                    {
                                        "key": "python_version",
                                        "value": "3.11"
                                    }
                                ],
                                "hidden": false
                            }
                        ]
                    },
                    "pod_config": {
                        "default": "tiny_cpu",
                        "values": [
                            {
                                "id": "tiny_cpu",
                                "displayName": "Tiny CPU",
                                "description": "Pod with 0.1 CPU, 128 Mb RAM",
                                "labels": [
                                    {
                                        "key": "cpu",
                                        "value": "100m"
                                    },
                                    {
                                        "key": "memory",
                                        "value": "128Mi"
                                    }
                                ],
                                "hidden": false
                            },
                            {
                                "id": "small_cpu",
                                "displayName": "Small CPU",
                                "description": "Pod with 1 CPU, 2 GB RAM",
                                "labels": [
                                    {
                                        "key": "cpu",
                                        "value": "1000m"
                                    },
                                    {
                                        "key": "memory",
                                        "value": "2Gi"
                                    }
                                ],
                                "hidden": false
                            },
                            {
                                "id": "big_gpu",
                                "displayName": "Big GPU",
                                "description": "Pod with 4 CPU, 16 GB RAM, and 1 GPU",
                                "labels": [
                                    {
                                        "key": "cpu",
                                        "value": "4000m"
                                    },
                                    {
                                        "key": "memory",
                                        "value": "16Gi"
                                    },
                                    {
                                        "key": "gpu",
                                        "value": "1"
                                    }
                                ],
                                "hidden": false
                            }
                        ]
                    }
                }
            }
        }
    ]
}

List Workspaces

curl -i localhost:4000/api/v1/workspaces

{
    "data": [
        {
            "name": "jupyterlab-workspace",
            "namespace": "default",
            "workspace_kind": {
                "name": "jupyterlab",
                "missing": false,
                "icon": {
                    "url": "/workspaces/backend/api/v1/workspacekinds/jupyterlab/assets/icon"
                },
                "logo": {
                    "url": "/workspaces/backend/api/v1/workspacekinds/jupyterlab/assets/logo"
                }
            },
            "defer_updates": false,
            "paused": false,
            "paused_time": 0,
            "state": "Unknown",
            "state_message": "",
            "pod_template": {
                "pod_metadata": {
                    "labels": {},
                    "annotations": {}
                },
                "volumes": {
                    "home": {
                        "pvc_name": "workspace-home-pvc",
                        "mount_path": "/home/jovyan",
                        "read_only": false
                    },
                    "data": [
                        {
                            "pvc_name": "workspace-data-pvc",
                            "mount_path": "/data/my-data",
                            "read_only": false
                        }
                    ]
                },
                "options": {
                    "image_config": {
                        "current": {
                            "id": "jupyterlab_scipy_190",
                            "display_name": "jupyter-scipy:v1.9.0",
                            "description": "JupyterLab, with SciPy Packages",
                            "labels": [
                                {
                                    "key": "python_version",
                                    "value": "3.11"
                                }
                            ]
                        }
                    },
                    "pod_config": {
                        "current": {
                            "id": "tiny_cpu",
                            "display_name": "Tiny CPU",
                            "description": "Pod with 0.1 CPU, 128 Mb RAM",
                            "labels": [
                                {
                                    "key": "cpu",
                                    "value": "100m"
                                },
                                {
                                    "key": "memory",
                                    "value": "128Mi"
                                }
                            ]
                        }
                    }
                }
            },
            "activity": {
                "last_activity": 0,
                "last_update": 0
            }
        }
    ]
}

List Workspaces (with missing WorkspaceKind)

curl -i localhost:4000/api/v1/workspaces

{
    "data": [
        {
            "name": "jupyterlab-workspace-bad",
            "namespace": "default",
            "workspace_kind": {
                "name": "jupyterlab-bad",
                "missing": true,
                "icon": {
                    "url": "/workspaces/backend/api/v1/workspacekinds/jupyterlab-bad/assets/icon"
                },
                "logo": {
                    "url": "/workspaces/backend/api/v1/workspacekinds/jupyterlab-bad/assets/logo"
                }
            },
            "defer_updates": false,
            "paused": false,
            "paused_time": 0,
            "state": "Unknown",
            "state_message": "",
            "pod_template": {
                "pod_metadata": {
                    "labels": {},
                    "annotations": {}
                },
                "volumes": {
                    "home": {
                        "pvc_name": "workspace-home-pvc",
                        "mount_path": "__UNKNOWN_HOME_MOUNT_PATH__",
                        "read_only": false
                    },
                    "data": [
                        {
                            "pvc_name": "workspace-data-pvc",
                            "mount_path": "/data/my-data",
                            "read_only": false
                        }
                    ]
                },
                "options": {
                    "image_config": {
                        "current": {
                            "id": "jupyterlab_scipy_190",
                            "display_name": "__UNKNOWN_IMAGE_CONFIG__",
                            "description": "__UNKNOWN_IMAGE_CONFIG__",
                            "labels": null
                        }
                    },
                    "pod_config": {
                        "current": {
                            "id": "tiny_cpu",
                            "display_name": "__UNKNOWN_POD_CONFIG__",
                            "description": "__UNKNOWN_POD_CONFIG__",
                            "labels": null
                        }
                    }
                }
            },
            "activity": {
                "last_activity": 0,
                "last_update": 0
            }
        }
    ]
}

@ederign
Copy link
Member

ederign commented Feb 4, 2025

Thank you, @thesuperzapper, for this PR.

The code looks good to me. I'm merging this to unblock other PRs. As this is a WIP, we can always accommodate changes and evolve it later.

I've tested the scenarios listed on README, and they are working fine.

@ederign
Copy link
Member

ederign commented Feb 4, 2025

/lgtm

@thesuperzapper
Copy link
Member Author

/approve

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ederign, thesuperzapper

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants