Skip to content

feat: add template setting to require active template version #10277

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

Merged
merged 32 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add template update plumbing
  • Loading branch information
sreya committed Oct 15, 2023
commit f31b2fdb9d931c56d646f4b0315bf5d6b7810ca6
2 changes: 1 addition & 1 deletion coderd/database/modelmethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (w Workspace) ApplicationConnectRBAC() rbac.Object {
}

func (w Workspace) WorkspaceBuildRBAC(transition WorkspaceTransition) rbac.Object {
// If a workspace is locked it cannot be built.
// If a workspace is dormant it cannot be built.
// However we need to allow stopping a workspace by a caller once a workspace
// is locked (e.g. for autobuild). Additionally, if a user wants to delete
// a locked workspace, they shouldn't have to have it unlocked first.
Expand Down
9 changes: 9 additions & 0 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ SET
autostart_block_days_of_week = $9,
failure_ttl = $10,
time_til_dormant = $11,
time_til_dormant_autodelete = $12
time_til_dormant_autodelete = $12,
require_promoted_version = $13
WHERE
id = $1
;
Expand Down
6 changes: 6 additions & 0 deletions coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ type TemplateScheduleOptions struct {
// workspaces whose dormant_at field violates the new template time_til_dormant_autodelete
// threshold.
UpdateWorkspaceDormantAt bool `json:"update_workspace_dormant_at"`
RequirePromotedVersion bool `json:"require_promoted_version"`
}

// TemplateScheduleStore provides an interface for retrieving template
Expand Down Expand Up @@ -200,6 +201,7 @@ func (*agplTemplateScheduleStore) Get(ctx context.Context, db database.Store, te
FailureTTL: 0,
TimeTilDormant: 0,
TimeTilDormantAutoDelete: 0,
RequirePromotedVersion: false,
}, nil
}

Expand All @@ -214,6 +216,9 @@ func (*agplTemplateScheduleStore) Set(ctx context.Context, db database.Store, tp

var template database.Template
err := db.InTx(func(db database.Store) error {
// TODO (JonA): This seems ripe for a bug. Should we not
// be reading the template as part of the tx and then also
// setting our isolation level to repeatable read?
err := db.UpdateTemplateScheduleByID(ctx, database.UpdateTemplateScheduleByIDParams{
ID: tpl.ID,
UpdatedAt: dbtime.Now(),
Expand All @@ -229,6 +234,7 @@ func (*agplTemplateScheduleStore) Set(ctx context.Context, db database.Store, tp
FailureTTL: tpl.FailureTTL,
TimeTilDormant: tpl.TimeTilDormant,
TimeTilDormantAutoDelete: tpl.TimeTilDormantAutoDelete,
RequirePromotedVersion: tpl.RequirePromotedVersion,
})
if err != nil {
return xerrors.Errorf("update template schedule: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions codersdk/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ type UpdateTemplateMeta struct {
// from the template. This is useful for preventing dormant workspaces being immediately
// deleted when updating the dormant_ttl field to a new, shorter value.
UpdateWorkspaceDormantAt bool `json:"update_workspace_dormant_at"`
// RequirePromotedVersion mandates workspaces built using this template
// use the latest promoted version of the template. This option has no
// effect on template admins.
RequirePromotedVersion bool `json:"require_promoted_version"`
}

type TemplateExample struct {
Expand Down
1 change: 1 addition & 0 deletions enterprise/coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
FailureTTL: int64(opts.FailureTTL),
TimeTilDormant: int64(opts.TimeTilDormant),
TimeTilDormantAutoDelete: int64(opts.TimeTilDormantAutoDelete),
RequirePromotedVersion: opts.RequirePromotedVersion,
})
if err != nil {
return xerrors.Errorf("update template schedule: %w", err)
Expand Down