Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6a08b1

Browse files
committed
add template update plumbing
1 parent 5786e81 commit f6a08b1

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

coderd/database/modelmethods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (w Workspace) ApplicationConnectRBAC() rbac.Object {
170170
}
171171

172172
func (w Workspace) WorkspaceBuildRBAC(transition WorkspaceTransition) rbac.Object {
173-
// If a workspace is locked it cannot be built.
173+
// If a workspace is dormant it cannot be built.
174174
// However we need to allow stopping a workspace by a caller once a workspace
175175
// is locked (e.g. for autobuild). Additionally, if a user wants to delete
176176
// a locked workspace, they shouldn't have to have it unlocked first.

coderd/database/queries.sql.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ SET
122122
autostop_requirement_weeks = $8,
123123
failure_ttl = $9,
124124
time_til_dormant = $10,
125-
time_til_dormant_autodelete = $11
125+
time_til_dormant_autodelete = $11,
126+
require_promoted_version = $12
126127
WHERE
127128
id = $1
128129
;

coderd/schedule/template.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type TemplateScheduleOptions struct {
118118
// workspaces whose dormant_at field violates the new template time_til_dormant_autodelete
119119
// threshold.
120120
UpdateWorkspaceDormantAt bool `json:"update_workspace_dormant_at"`
121+
RequirePromotedVersion bool `json:"require_promoted_version"`
121122
}
122123

123124
// TemplateScheduleStore provides an interface for retrieving template
@@ -163,6 +164,7 @@ func (*agplTemplateScheduleStore) Get(ctx context.Context, db database.Store, te
163164
FailureTTL: 0,
164165
TimeTilDormant: 0,
165166
TimeTilDormantAutoDelete: 0,
167+
RequirePromotedVersion: false,
166168
}, nil
167169
}
168170

@@ -177,6 +179,9 @@ func (*agplTemplateScheduleStore) Set(ctx context.Context, db database.Store, tp
177179

178180
var template database.Template
179181
err := db.InTx(func(db database.Store) error {
182+
// TODO (JonA): This seems ripe for a bug. Should we not
183+
// be reading the template as part of the tx and then also
184+
// setting our isolation level to repeatable read?
180185
err := db.UpdateTemplateScheduleByID(ctx, database.UpdateTemplateScheduleByIDParams{
181186
ID: tpl.ID,
182187
UpdatedAt: dbtime.Now(),
@@ -191,6 +196,7 @@ func (*agplTemplateScheduleStore) Set(ctx context.Context, db database.Store, tp
191196
FailureTTL: tpl.FailureTTL,
192197
TimeTilDormant: tpl.TimeTilDormant,
193198
TimeTilDormantAutoDelete: tpl.TimeTilDormantAutoDelete,
199+
RequirePromotedVersion: tpl.RequirePromotedVersion,
194200
})
195201
if err != nil {
196202
return xerrors.Errorf("update template schedule: %w", err)

codersdk/templates.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ type UpdateTemplateMeta struct {
212212
// from the template. This is useful for preventing dormant workspaces being immediately
213213
// deleted when updating the dormant_ttl field to a new, shorter value.
214214
UpdateWorkspaceDormantAt bool `json:"update_workspace_dormant_at"`
215+
// RequirePromotedVersion mandates workspaces built using this template
216+
// use the latest promoted version of the template. This option has no
217+
// effect on template admins.
218+
RequirePromotedVersion bool `json:"require_promoted_version"`
215219
}
216220

217221
type TemplateExample struct {

enterprise/coderd/schedule/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
139139
FailureTTL: int64(opts.FailureTTL),
140140
TimeTilDormant: int64(opts.TimeTilDormant),
141141
TimeTilDormantAutoDelete: int64(opts.TimeTilDormantAutoDelete),
142+
RequirePromotedVersion: opts.RequirePromotedVersion,
142143
})
143144
if err != nil {
144145
return xerrors.Errorf("update template schedule: %w", err)

0 commit comments

Comments
 (0)