Skip to content

Commit 4072d22

Browse files
authored
feat: support dynamic parameters on create template request (#18636)
Future work is to add this checkbox to the UI to opt into dynamic parameters from the first template create.
1 parent 91aa583 commit 4072d22

File tree

13 files changed

+71
-39
lines changed

13 files changed

+71
-39
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/coderdtest/dynamicparameters.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,25 @@ func DynamicParameterTemplate(t *testing.T, client *codersdk.Client, org uuid.UU
5050
})
5151
AwaitTemplateVersionJobCompleted(t, client, version.ID)
5252

53-
tplID := args.TemplateID
53+
var tpl codersdk.Template
54+
var err error
55+
5456
if args.TemplateID == uuid.Nil {
55-
tpl := CreateTemplate(t, client, org, version.ID)
56-
tplID = tpl.ID
57+
tpl = CreateTemplate(t, client, org, version.ID, func(request *codersdk.CreateTemplateRequest) {
58+
request.UseClassicParameterFlow = ptr.Ref(false)
59+
})
60+
} else {
61+
tpl, err = client.UpdateTemplateMeta(t.Context(), args.TemplateID, codersdk.UpdateTemplateMeta{
62+
UseClassicParameterFlow: ptr.Ref(false),
63+
})
64+
require.NoError(t, err)
5765
}
5866

59-
var err error
60-
tpl, err := client.UpdateTemplateMeta(t.Context(), tplID, codersdk.UpdateTemplateMeta{
61-
UseClassicParameterFlow: ptr.Ref(false),
62-
})
63-
require.NoError(t, err)
64-
6567
err = client.UpdateActiveTemplateVersion(t.Context(), tpl.ID, codersdk.UpdateActiveTemplateVersion{
6668
ID: version.ID,
6769
})
6870
require.NoError(t, err)
71+
require.Equal(t, tpl.UseClassicParameterFlow, false, "template should use dynamic parameters")
6972

7073
return tpl, version
7174
}

coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func Template(t testing.TB, db database.Store, seed database.Template) database.
100100
DisplayName: takeFirst(seed.DisplayName, testutil.GetRandomName(t)),
101101
AllowUserCancelWorkspaceJobs: seed.AllowUserCancelWorkspaceJobs,
102102
MaxPortSharingLevel: takeFirst(seed.MaxPortSharingLevel, database.AppSharingLevelOwner),
103+
UseClassicParameterFlow: takeFirst(seed.UseClassicParameterFlow, true),
103104
})
104105
require.NoError(t, err, "insert template")
105106

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9330,7 +9330,7 @@ func (q *FakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTempl
93309330
AllowUserAutostart: true,
93319331
AllowUserAutostop: true,
93329332
MaxPortSharingLevel: arg.MaxPortSharingLevel,
9333-
UseClassicParameterFlow: true,
9333+
UseClassicParameterFlow: arg.UseClassicParameterFlow,
93349334
}
93359335
q.templates = append(q.templates, template)
93369336
return nil

coderd/database/queries.sql.go

Lines changed: 5 additions & 2 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ INSERT INTO
9898
group_acl,
9999
display_name,
100100
allow_user_cancel_workspace_jobs,
101-
max_port_sharing_level
101+
max_port_sharing_level,
102+
use_classic_parameter_flow
102103
)
103104
VALUES
104-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);
105+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16);
105106

106107
-- name: UpdateTemplateActiveVersionByID :exec
107108
UPDATE

coderd/templates.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,20 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
197197
return
198198
}
199199

200+
// Default is true until dynamic parameters are promoted to stable.
201+
useClassicParameterFlow := ptr.NilToDefault(createTemplate.UseClassicParameterFlow, true)
202+
200203
// Make a temporary struct to represent the template. This is used for
201204
// auditing if any of the following checks fail. It will be overwritten when
202205
// the template is inserted into the db.
203206
templateAudit.New = database.Template{
204-
OrganizationID: organization.ID,
205-
Name: createTemplate.Name,
206-
Description: createTemplate.Description,
207-
CreatedBy: apiKey.UserID,
208-
Icon: createTemplate.Icon,
209-
DisplayName: createTemplate.DisplayName,
207+
OrganizationID: organization.ID,
208+
Name: createTemplate.Name,
209+
Description: createTemplate.Description,
210+
CreatedBy: apiKey.UserID,
211+
Icon: createTemplate.Icon,
212+
DisplayName: createTemplate.DisplayName,
213+
UseClassicParameterFlow: useClassicParameterFlow,
210214
}
211215

212216
_, err := api.Database.GetTemplateByOrganizationAndName(ctx, database.GetTemplateByOrganizationAndNameParams{
@@ -404,6 +408,7 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
404408
Icon: createTemplate.Icon,
405409
AllowUserCancelWorkspaceJobs: allowUserCancelWorkspaceJobs,
406410
MaxPortSharingLevel: maxPortShareLevel,
411+
UseClassicParameterFlow: useClassicParameterFlow,
407412
})
408413
if err != nil {
409414
return xerrors.Errorf("insert template: %s", err)

coderd/templates_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func TestPostTemplateByOrganization(t *testing.T) {
7777
assert.Equal(t, expected.Name, got.Name)
7878
assert.Equal(t, expected.Description, got.Description)
7979
assert.Equal(t, expected.ActivityBumpMillis, got.ActivityBumpMillis)
80+
assert.Equal(t, expected.UseClassicParameterFlow, true) // Current default is true
8081

8182
require.Len(t, auditor.AuditLogs(), 3)
8283
assert.Equal(t, database.AuditActionCreate, auditor.AuditLogs()[0].Action)

codersdk/organizations.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ type CreateTemplateRequest struct {
200200
// MaxPortShareLevel allows optionally specifying the maximum port share level
201201
// for workspaces created from the template.
202202
MaxPortShareLevel *WorkspaceAgentPortShareLevel `json:"max_port_share_level"`
203+
204+
// UseClassicParameterFlow allows optionally specifying whether
205+
// the template should use the classic parameter flow. The default if unset is
206+
// true, and is why `*bool` is used here. When dynamic parameters becomes
207+
// the default, this will default to false.
208+
UseClassicParameterFlow *bool `json:"template_use_classic_parameter_flow,omitempty"`
203209
}
204210

205211
// CreateWorkspaceRequest provides options for creating a new workspace.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy