Skip to content

Conversation

@asaadbalum
Copy link

This PR adds the POST /api/v1/workspacekinds endpoint for creating a WorkspaceKind from a raw YAML upload.

The implementation adds a Create() method to the repository and the CreateWorkspaceKindHandler to process the request. The corresponding integration tests verify the success path using a static file payload and also cover key failure cases.

closes: #278

@andyatmiami
Copy link
Contributor

Tested happy path via the Swagger UI generated from this PR and observed a WorkspaceKind was successfully created.

image

➜ manifests/ $ kubectl get workspacekinds/rstudio
NAME      WORKSPACES   DEPRECATED   HIDDEN
rstudio   0            false        false

Comment on lines 179 to 263
if err != nil {
a.serverErrorResponse(w, r, err)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Error propagation in the case of the workspace kind already existing is not working... when I "spam" the Swagger UI to create the same workspace kind repeatedly - its returning a 500 error - which is not expected behavior

image

You can refer to the create workspace function (amongst other places) to see how we properly identify an error from a repository function and ensure its encoded appropriately for return to client here:

Copy link
Author

Choose a reason for hiding this comment

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

I've updated the CreateWorkspaceKindHandler to specifically check for the ErrWorkspaceKindAlreadyExists from the repository. It now correctly returns a 409 Conflict in this case.


// === Validate name exists in YAML ===
if newWsk.Name == "" {
a.failedValidationResponse(w, r, "'.metadata.name' is a required field", field.ErrorList{
Copy link
Contributor

@andyatmiami andyatmiami Jun 23, 2025

Choose a reason for hiding this comment

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

I'm not sure we want to use failedValidationResponse here... as it returns a 422 error..

Here is a case where I supplied an obviously invalid request body and got a 422 back:
image

(1) 422 is NOT listed as a possible HTTP response status code in our Swagger annotations
(2) I believe a 400 is a better/more natural status code to begin with here (but maybe I am old/out of touch/wrong?)

image image

Copy link
Author

Choose a reason for hiding this comment

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

400 is more appropriate here. I've changed the handler to use badRequestResponse for the missing name validation, so it now correctly returns a 400 Bad Request.

Copy link
Member

@thesuperzapper thesuperzapper Jul 4, 2025

Choose a reason for hiding this comment

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

I disagree, and think the validation 422 is better because we include specific field references with where the error occurred.

@andyatmiami
Copy link
Contributor

/lgtm

Thanks for promptly addressing all feedback.

I have verified the following scenarios:

  • [happy path] can create workspacekind from YAML via API
  • [error path] invalid content type return 415
  • [error path] providing non-yaml input returns sensible error
  • [error path] providing invalid workspacekind manifest returns sensible error
  • [error path] providing wrong kind of (otherwise valid) manifest provides sensible error
  • [error path] trying to create a resource whose name already exists returns sensible error

@thesuperzapper thesuperzapper changed the title feat(ws): Notebooks 2.0 // Backend // API that allows frontend to upload a YAML file containing a full new WorkspaceKind definition feat(ws): backend api to create wsk with YAML Jun 26, 2025
…oad a YAML file containing a full new WorkspaceKind definition

Signed-off-by: Asaad Balum <[email protected]>
Signed-off-by: Mathew Wicks <[email protected]>
@google-oss-prow google-oss-prow bot added size/XL and removed size/L labels Jul 4, 2025
@thesuperzapper
Copy link
Member

@asaadbalum thanks for this, I worked with @andyatmiami to push 50d6f9b which factors the logic out a bit and fixes some of the tests, I have also reverted to using application/yaml as the media type, as this is what upstream Kubernetes uses.

Feel free to review and indicate when you are ready to merge.

@andyatmiami
Copy link
Contributor

/lgtm

re-validated same test cases I did previously and can confirm behavior is as intended.

@google-oss-prow google-oss-prow bot added the lgtm label Jul 4, 2025
@thesuperzapper
Copy link
Member

/approve

@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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

/ok-to-test

@google-oss-prow google-oss-prow bot merged commit d38b24c into kubeflow:notebooks-v2 Jul 6, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in Kubeflow Notebooks Jul 6, 2025
bhaktinarvekar pushed a commit to bhaktinarvekar/notebooks that referenced this pull request Sep 14, 2025
* feat(ws): Notebooks 2.0 // Backend // API that allows frontend to upload a YAML file containing a full new WorkspaceKind definition

Signed-off-by: Asaad Balum <[email protected]>

* mathew: 1

Signed-off-by: Mathew Wicks <[email protected]>

---------

Signed-off-by: Asaad Balum <[email protected]>
Signed-off-by: Mathew Wicks <[email protected]>
Co-authored-by: Mathew Wicks <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved area/backend area - related to backend components area/v2 area - version - kubeflow notebooks v2 lgtm ok-to-test size/XL

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants