Skip to content

feat: cli: allow editing template metadata - #2159

Merged
johnstcn merged 4 commits into
mainfrom
cj/1433/edit-template-meta
Jun 8, 2022
Merged

johnstcn merged 4 commits into
mainfrom
cj/1433/edit-template-meta

Conversation

@johnstcn

@johnstcn johnstcn commented Jun 8, 2022

Copy link
Copy Markdown
Member

This PR adds a CLI command template edit which allows updating the following metadata fields of a template:

  • Description
  • Max TTL
  • Min Autostart Interval

@johnstcn johnstcn self-assigned this Jun 8, 2022
@johnstcn
johnstcn requested a review from a team June 8, 2022 11:44
@johnstcn
johnstcn marked this pull request as ready for review June 8, 2022 11:44
@johnstcn
johnstcn requested a review from a team as a code owner June 8, 2022 11:44

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the omitempty fixes, this LGTM! Had some small suggestions and questions but nothing major.

Comment thread coderd/templates.go Resolved
Comment thread coderd/templates.go Resolved
Comment thread codersdk/templates.go Resolved
Comment thread coderd/templates.go
minAutostartInterval = time.Duration(template.MinAutostartInterval)
}

if err := s.UpdateTemplateMetaByID(r.Context(), database.UpdateTemplateMetaByIDParams{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: Do we actually want to mutate the templates here, or should we update the template to a new revision? Motivation:

  • Mutation does not leave a trace of the change
  • It can become hard to explain how changes in template metadata affect (or don't affect) running workspaces

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Mutation does not leave a trace of the change

Audit logging will cover this, I think

It can become hard to explain how changes in template metadata affect (or don't affect) running workspaces

I would argue strongly that template metadata changes should never affect running workspaces. However, if a template owner edits max_ttl or min_autostart_duration then edits to workspaces, running or not, will be affected.

Additionally, as things stand this would require moving the fields max_ttl and min_autostop_duration_ms to the template_versions table, with all of the associated plumbing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Audit logging will cover this, I think

Ok, that's great! As long as there's a trace I think that's good enough.

I would argue strongly that template metadata changes should never affect running workspaces. However, if a template owner edits max_ttl or min_autostart_duration then edits to workspaces, running or not, will be affected.

This sounds like it would be fine, for now at least. This is probably the behavior the template editor is looking for. Would someone editing a workspace be able to observe the change when they make the edit? If not that part might be a bit unexpected but otherwise OK IMO.

Additionally, as things stand this would require moving the fields max_ttl and min_autostop_duration_ms to the template_versions table, with all of the associated plumbing.

That sounds like a bigger issue and not something we want to do in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Would someone editing a workspace be able to observe the change when they make the edit?

Depends if they have the permission to view the template, I guess 🤔 which should be true as far as I know.

Comment thread coderd/templates_test.go Resolved
Comment thread site/src/api/typesGenerated.ts Resolved
Comment thread coderd/templates.go Resolved
Comment thread cli/templateedit.go Resolved
Comment thread cli/templateedit.go Resolved
Comment thread cli/templateedit.go Resolved
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we not have a coder templates show?

@johnstcn

johnstcn commented Jun 8, 2022

Copy link
Copy Markdown
Member Author

Do we not have a coder templates show?

We do not, apparently

Comment thread coderd/templates.go
// Fetch workspace counts
workspaceCounts, err := s.GetWorkspaceOwnerCountsByTemplateIDs(r.Context(), []uuid.UUID{template.ID})
if errors.Is(err, sql.ErrNoRows) {
if xerrors.Is(err, sql.ErrNoRows) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, should we add some linting for this? The actual xerrors.Is function is marked deprecated, and we have a lot of mixed usage in the code-base:

❯ rg xerrors.Is | wc -l
20

❯ rg '[^x]errors.Is' | wc -l
104

(Note: I'm not suggesting we fix the usage in this PR).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

AFAIK there are Reasons for using that instead of the original; something about stacktraces.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, there was a case for using Errorf and New at least, to get the stack trace. But the others are deprecated and are likely not updated in case there are any changes to stdlib. Interestingly, I now noticed Errorf was also marked deprecated in favor of fmt.Errorf even though the latter does not include a stack trace. Weird.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, might be a good topic for dicussion!

@Emyrk Emyrk Jun 8, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mafredri we can add a linter for it easy if we want to use xerrors.As/Is over errors.As/Is

	m.Match("errors.$f($*_)").
		Report("Use xerrors.$f to provide additional stacktrace information!")

@johnstcn
johnstcn merged commit 8cfe223 into main Jun 8, 2022
@johnstcn
johnstcn deleted the cj/1433/edit-template-meta branch June 8, 2022 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants