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

fix(ws): update JSON payload for listing workspaces #134

Merged

Conversation

mohamedch7
Copy link

Fix: Update Workspace Model and JSON Payload Structure

This PR addresses issue #127 by refactoring the workspace model and adjusting the JSON payload structure to align with the updated API requirements.

Changes Made

  • Workspace Model Updates:

    • Introduced new fields: WorkspaceKind, PodTemplate, Activity, and Volumes.
    • Updated nested models (PodMetadata, ImageConfig, PodConfig) for improved modularity.
  • Handler Updates:

    • Refactored test cases in workspaces_handler_test.go to validate the new model and payload structure.
  • Repository Adjustments:

    • Updated the CreateWorkspace method in workspaces.go to reflect the new model structure.
    • Ensured compatibility with nested fields during workspace creation.
  • Payload Adjustments:

    • Ensured responses match the updated API specification.

Impact

  • Aligns backend structure with updated API expectations.

Testing

  • Unit tests in workspaces_handler_test.go updated to include new cases.

@ederign
Copy link
Member

ederign commented Nov 27, 2024

@mohamedch7 thank you so much for the contribution! I'll look it before end of the week.

@thesuperzapper
Copy link
Member

@mohamedch7 once we merge #137 (hopefully tomorrow) please rebase this PR so you get the new linting (and make sure your PR passes a make lint).

Copy link
Member

@ederign ederign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace: item.Namespace,
WorkspaceKind: WorkspaceKind{
Name: item.Spec.Kind,
Type: item.Spec.PodTemplate.Options.ImageConfig,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

workspaces/backend/internal/models/workspaces.go Outdated Show resolved Hide resolved
PodTemplate: PodTemplate{
PodMetadata: &PodMetadata{
Labels: item.Spec.PodTemplate.PodMetadata.Labels,
Annotations: item.Spec.PodTemplate.PodMetadata.Annotations,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"labels": null,
"annotations": null

},
Volumes: &Volumes{
Home: &DataVolumeModel{
PvcName: item.Spec.PodTemplate.Volumes.Data[0].PVCName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Home is not Volumes.Data[0], but instead defined by kind:
the mount path is defined in the WorkspaceKind under
## spec.podTemplate.volumeMounts.home

Copy link
Author

@mohamedch7 mohamedch7 Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fetch WorkspaceKind then use it, right ?
57d4485

MountPath: item.Spec.PodTemplate.Volumes.Data[0].MountPath,
ReadOnly: *item.Spec.PodTemplate.Volumes.Data[0].ReadOnly,
},
Data: dataVolumes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to don't list 'home' here.

},
PodConfig: &PodConfig{
Current: item.Spec.PodTemplate.Options.PodConfig,
Desired: item.Spec.PodTemplate.Options.PodConfig,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be:
Pod Template Options:
Image Config:
Desired: jupyterlab_scipy_190

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(on status)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@ederign
Copy link
Member

ederign commented Dec 2, 2024

Also, make sure to rebase it to include the new linting etc.

@thesuperzapper
Copy link
Member

@mohamedch7 you should be able to rebase it to head of notebooks-v2 now, and then make sure make lint and make test pass.

@mohamedch7 mohamedch7 force-pushed the update-workspace-json branch from 4a4c56f to fd1fb92 Compare December 19, 2024 12:44
Copy link
Member

@ederign ederign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohamedch7 I'm sorry for the delay on this PR. I was in a long PTO but I'm back.

I just asked here a small changes. I'll review as soon as you send the PR. And please, don't forget to sign the commits.

models.NewWorkspaceModelFromWorkspace(workspace1),
models.NewWorkspaceModelFromWorkspace(workspace2),
models.NewWorkspaceModelFromWorkspace(workspace3),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our model should only be responsible for translate k8s object for our DTOs/pojos. We should not add any extra logic there. Could you please pass the kind as a parameter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

models.NewWorkspaceModelFromWorkspace(workspace2),
models.NewWorkspaceModelFromWorkspace(workspace3),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace1),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace2),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

models.NewWorkspaceModelFromWorkspace(workspace3),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace1),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace2),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace3),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -256,8 +256,8 @@ var _ = Describe("Workspaces Handler", func() {
Expect(k8sClient.Get(ctx, workspaceKey2, workspace2)).To(Succeed())

expectedWorkspaces := []models.WorkspaceModel{
models.NewWorkspaceModelFromWorkspace(workspace1),
models.NewWorkspaceModelFromWorkspace(workspace2),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

models.NewWorkspaceModelFromWorkspace(workspace1),
models.NewWorkspaceModelFromWorkspace(workspace2),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace1),
models.NewWorkspaceModelFromWorkspace(ctx, k8sClient, workspace2),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

t := time.Unix(item.Status.Activity.LastActivity, 0)
formattedLastActivity := t.Format("2006-01-02 15:04:05 MST")
func NewWorkspaceModelFromWorkspace(ctx context.Context, cl client.Client, item *kubefloworgv1beta1.Workspace) WorkspaceModel {
wsk := &kubefloworgv1beta1.WorkspaceKind{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this lines to repository.

@@ -69,7 +69,7 @@ func (r *WorkspaceRepository) GetWorkspaces(ctx context.Context, namespace strin

workspacesModels := make([]models.WorkspaceModel, len(workspaceList.Items))
for i, item := range workspaceList.Items {
workspaceModel := models.NewWorkspaceModelFromWorkspace(&item)
workspaceModel := models.NewWorkspaceModelFromWorkspace(ctx, r.client, &item)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as others.

@@ -53,7 +53,7 @@ func (r *WorkspaceRepository) GetWorkspace(ctx context.Context, namespace string
return models.WorkspaceModel{}, err
}

workspaceModel := models.NewWorkspaceModelFromWorkspace(workspace)
workspaceModel := models.NewWorkspaceModelFromWorkspace(ctx, r.client, workspace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as others.

@@ -100,34 +100,34 @@ func (r *WorkspaceRepository) CreateWorkspace(ctx context.Context, workspaceMode
Name: workspaceModel.Name,
Namespace: workspaceModel.Namespace,
// TODO: the pod and workspace labels should be separated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove my old TODO here?

workspaces/backend/internal/repositories/workspaces.go Outdated Show resolved Hide resolved
@yehudit1987
Copy link

yehudit1987 commented Jan 19, 2025

Hi @mohamedch7, please, don't forget to sign the commits, you have unsigned commits.

@ederign
Copy link
Member

ederign commented Jan 22, 2025

@mohamedch7, can you please sign the commit?

@mohamedch7 mohamedch7 force-pushed the update-workspace-json branch from fbc34d7 to 5bc2a17 Compare January 23, 2025 16:12
Copy link
Member

@thesuperzapper thesuperzapper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interest of moving this forward, I will approve.

There is one big issue I found (see comments) but other than that I expect we will be rewriting a lot of this anyway, so its good to have a base to work from.

workspaceModel := models.NewWorkspaceModelFromWorkspace(&item)
workspacesModels[i] = workspaceModel
kind := &kubefloworgv1beta1.WorkspaceKind{}
if err := r.client.Get(ctx, client.ObjectKey{Name: item.Spec.Kind}, kind); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not guaranteed that a WorkspaceKind will actually exist, even if it has been referenced by a Workspace (things can happen which bypass the validation webhook).

So in a follow-up PR, we need to gracefully handle Workspaces with missing WorkspaceKinds (e.g. still list them but indicate that we can't fully process them).

workspaceModel := models.NewWorkspaceModelFromWorkspace(&item)
workspacesModels[i] = workspaceModel
kind := &kubefloworgv1beta1.WorkspaceKind{}
if err := r.client.Get(ctx, client.ObjectKey{Name: item.Spec.Kind}, kind); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea here, WSK might be missing.

workspaceModel := models.NewWorkspaceModelFromWorkspace(workspace)
return workspaceModel, nil
kind := &kubefloworgv1beta1.WorkspaceKind{}
if err := r.client.Get(ctx, client.ObjectKey{Name: workspace.Spec.Kind}, kind); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea here, WSK might be missing.

@@ -140,7 +144,12 @@ func (r *WorkspaceRepository) CreateWorkspace(ctx context.Context, workspaceMode
return models.WorkspaceModel{}, err
}

return models.NewWorkspaceModelFromWorkspace(workspace), nil
kind := &kubefloworgv1beta1.WorkspaceKind{}
if err := r.client.Get(ctx, client.ObjectKey{Name: workspace.Spec.Kind}, kind); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea here, WSK might be missing.

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

@thesuperzapper
Copy link
Member

/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Jan 24, 2025
@google-oss-prow google-oss-prow bot merged commit d06762d into kubeflow:notebooks-v2 Jan 24, 2025
5 checks passed
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.

4 participants