- 
                Notifications
    You must be signed in to change notification settings 
- Fork 67
feat(ws): backend api to create wsk with YAML #434
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
Conversation
eb23929    to
    9db9908      
    Compare
  
            
          
                workspaces/backend/internal/repositories/workspacekinds/repo.go
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | if err != nil { | ||
| a.serverErrorResponse(w, r, err) | ||
| return | ||
| } | 
There was a problem hiding this comment.
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
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:
There was a problem hiding this comment.
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{ | 
There was a problem hiding this comment.
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:

(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?)
 
 
    There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| /lgtm Thanks for promptly addressing all feedback. I have verified the following scenarios: 
 | 
1d2e1a3    to
    1d84c91      
    Compare
  
    …oad a YAML file containing a full new WorkspaceKind definition Signed-off-by: Asaad Balum <[email protected]>
Signed-off-by: Mathew Wicks <[email protected]>
| @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  Feel free to review and indicate when you are ready to merge. | 
| /lgtm re-validated same test cases I did previously and can confirm behavior is as intended. | 
| /approve | 
| [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  | 
| /ok-to-test | 
* 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]>


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