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

Skip to content

Commit f31b2fd

Browse files
committed
add template update plumbing
1 parent eb5cb38 commit f31b2fd

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

coderd/database/modelmethods.go

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

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

coderd/database/queries.sql.go

Lines changed: 9 additions & 0 deletions
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
@@ -123,7 +123,8 @@ SET
123123
autostart_block_days_of_week = $9,
124124
failure_ttl = $10,
125125
time_til_dormant = $11,
126-
time_til_dormant_autodelete = $12
126+
time_til_dormant_autodelete = $12,
127+
require_promoted_version = $13
127128
WHERE
128129
id = $1
129130
;

coderd/schedule/template.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ type TemplateScheduleOptions struct {
151151
// workspaces whose dormant_at field violates the new template time_til_dormant_autodelete
152152
// threshold.
153153
UpdateWorkspaceDormantAt bool `json:"update_workspace_dormant_at"`
154+
RequirePromotedVersion bool `json:"require_promoted_version"`
154155
}
155156

156157
// TemplateScheduleStore provides an interface for retrieving template
@@ -200,6 +201,7 @@ func (*agplTemplateScheduleStore) Get(ctx context.Context, db database.Store, te
200201
FailureTTL: 0,
201202
TimeTilDormant: 0,
202203
TimeTilDormantAutoDelete: 0,
204+
RequirePromotedVersion: false,
203205
}, nil
204206
}
205207

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

215217
var template database.Template
216218
err := db.InTx(func(db database.Store) error {
219+
// TODO (JonA): This seems ripe for a bug. Should we not
220+
// be reading the template as part of the tx and then also
221+
// setting our isolation level to repeatable read?
217222
err := db.UpdateTemplateScheduleByID(ctx, database.UpdateTemplateScheduleByIDParams{
218223
ID: tpl.ID,
219224
UpdatedAt: dbtime.Now(),
@@ -229,6 +234,7 @@ func (*agplTemplateScheduleStore) Set(ctx context.Context, db database.Store, tp
229234
FailureTTL: tpl.FailureTTL,
230235
TimeTilDormant: tpl.TimeTilDormant,
231236
TimeTilDormantAutoDelete: tpl.TimeTilDormantAutoDelete,
237+
RequirePromotedVersion: tpl.RequirePromotedVersion,
232238
})
233239
if err != nil {
234240
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
@@ -221,6 +221,10 @@ type UpdateTemplateMeta struct {
221221
// from the template. This is useful for preventing dormant workspaces being immediately
222222
// deleted when updating the dormant_ttl field to a new, shorter value.
223223
UpdateWorkspaceDormantAt bool `json:"update_workspace_dormant_at"`
224+
// RequirePromotedVersion mandates workspaces built using this template
225+
// use the latest promoted version of the template. This option has no
226+
// effect on template admins.
227+
RequirePromotedVersion bool `json:"require_promoted_version"`
224228
}
225229

226230
type TemplateExample struct {

enterprise/coderd/schedule/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
151151
FailureTTL: int64(opts.FailureTTL),
152152
TimeTilDormant: int64(opts.TimeTilDormant),
153153
TimeTilDormantAutoDelete: int64(opts.TimeTilDormantAutoDelete),
154+
RequirePromotedVersion: opts.RequirePromotedVersion,
154155
})
155156
if err != nil {
156157
return xerrors.Errorf("update template schedule: %w", err)

0 commit comments

Comments
 (0)