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: Update workspace for templates server side #9272

Merged
merged 4 commits into from
May 3, 2024

Conversation

gt2345
Copy link
Contributor

@gt2345 gt2345 commented Apr 30, 2024

Ticket

MD-379

Description

In order to support move templates between workspaces, update PutTemplate to take workspace id.

Test Plan

Change workspace id for a template through /api/v1/templates/{templateName} endpoint.
Using invalid workspace id should not go through.

Checklist

  • Changes have been manually QA'd
  • User-facing API changes need the "User-facing API Change" label.
  • Release notes should be added as a separate file under docs/release-notes/.
    See Release Note for details.
  • Licenses should be included for new code which was copied and/or modified from any external code.

@gt2345 gt2345 requested a review from a team as a code owner April 30, 2024 20:42
@gt2345 gt2345 requested a review from kkunapuli April 30, 2024 20:42
@cla-bot cla-bot bot added the cla-signed label Apr 30, 2024
@gt2345 gt2345 requested a review from stoksc April 30, 2024 20:43
Copy link

netlify bot commented Apr 30, 2024

Deploy Preview for determined-ui canceled.

Name Link
🔨 Latest commit 15f08b4
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/6633befe8f683a0008c5a403

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 75.47170% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 44.60%. Comparing base (2905180) to head (15f08b4).
Report is 18 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9272   +/-   ##
=======================================
  Coverage   44.60%   44.60%           
=======================================
  Files        1273     1273           
  Lines      155831   155852   +21     
  Branches     2439     2439           
=======================================
+ Hits        69504    69520   +16     
- Misses      86088    86093    +5     
  Partials      239      239           
Flag Coverage Δ
backend 41.76% <75.47%> (+0.01%) ⬆️
harness 64.05% <ø> (ø)
web 35.04% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
harness/determined/common/api/bindings.py 40.22% <ø> (ø)
master/internal/templates/api.go 71.65% <75.47%> (+2.38%) ⬆️

... and 2 files with indirect coverage changes

case errors.Is(err, db.ErrNotFound):
_, err := a.PostTemplate(ctx, &apiv1.PostTemplateRequest{Template: req.Template})
if err != nil {
return nil, err
}
return &apiv1.PutTemplateResponse{Template: req.Template}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a special case?

permErr, err := AuthZProvider.Get().CanUpdateTemplate(
ctx, user, model.AccessScopeID(tpl.WorkspaceID),
)
switch {
Copy link
Contributor

@kkunapuli kkunapuli May 1, 2024

Choose a reason for hiding this comment

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

Why use a switch instead of if statements here? (I'm wondering if it's a style convention I'm not familiar with?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part was moved from other places, I saw we use both switch and if under similar circumstances.

req := &apiv1.PatchTemplateConfigRequest{
TemplateName: req.Template.Name,
Config: req.Template.Config,
user, _, err := grpcutil.GetUser(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Since there's more complexity in the default case, and nothing else happens in the function, I would prefer simplifying the default case a bit. Either leave off default: and let everything that happens in default: happen as part of normal function execution. Or, if it makes sense as a logical unit, move some of it into separate functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure


resp1, err := api.PutTemplate(ctx, &apiv1.PutTemplateRequest{Template: input})
require.NoError(t, err)
require.Equal(t, resp1.Template.WorkspaceId, int32(w.ID))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test for an invalid workspace ID too if it doesn't already exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

exists, err := workspace.Exists(ctx, int(workspaceID))
switch {
case err != nil:
return fmt.Errorf("failed to check workspace %d: %w", workspaceID, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about workspace check failed instead of failed to check workspace? I think it's a little simpler and more descriptive. When I first read failed to check workspace I thought it was saying the user had failed to do something and then I read it again.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now that this function is not new as much as moved ... feel free to ignore if you'd prefer.

)
switch {
case err != nil:
return fmt.Errorf("failed to check for permissions: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to above, how about permission check failed?

)
switch {
case err != nil:
return nil, fmt.Errorf("failed to check for permissions: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

permission check failed? (similar comments below with more explanation)

Copy link
Contributor

@kkunapuli kkunapuli left a comment

Choose a reason for hiding this comment

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

Great work!

@gt2345 gt2345 merged commit b0a008e into main May 3, 2024
87 of 99 checks passed
@gt2345 gt2345 deleted the gt/379-patch-template-ws branch May 3, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants