-
Notifications
You must be signed in to change notification settings - Fork 881
feat: track resource replacements when claiming a prebuilt workspace #17571
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
base: main
Are you sure you want to change the base?
Changes from all commits
b32923a
0b0830f
256395a
61ef61a
a66559f
222892b
f34e011
5168c01
41e5e0c
b29e8fa
b31ed5e
adf98d2
f24aef0
70f9a53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DELETE FROM notification_templates WHERE id = '89d9745a-816e-4695-a17f-3d0a229e2b8d'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
INSERT INTO notification_templates | ||
(id, name, title_template, body_template, "group", actions) | ||
VALUES ('89d9745a-816e-4695-a17f-3d0a229e2b8d', | ||
'Prebuilt Workspace Resource Replaced', | ||
E'There might be a problem with a recently claimed prebuilt workspace', | ||
$$ | ||
Workspace **{{.Labels.workspace}}** was claimed from a prebuilt workspace by **{{.Labels.claimant}}**. | ||
|
||
During the claim, Terraform destroyed and recreated the following resources | ||
because one or more immutable attributes changed: | ||
|
||
{{range $resource, $paths := .Data.replacements -}} | ||
- _{{ $resource }}_ was replaced due to changes to _{{ $paths }}_ | ||
{{end}} | ||
|
||
When Terraform must change an immutable attribute, it replaces the entire resource. | ||
If you’re using prebuilds to speed up provisioning, unexpected replacements will slow down | ||
workspace startup—even when claiming a prebuilt environment. | ||
|
||
For tips on preventing replacements and improving claim performance, see [this guide](https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces.md#preventing-resource-replacement). | ||
|
||
NOTE: this prebuilt workspace used the **{{.Labels.preset}}** preset. | ||
$$, | ||
'Template Events', | ||
'[ | ||
{ | ||
"label": "View workspace build", | ||
"url": "{{base_url}}/@{{.Labels.claimant}}/{{.Labels.workspace}}/builds/{{.Labels.workspace_build_num}}" | ||
}, | ||
{ | ||
"label": "View template version", | ||
"url": "{{base_url}}/templates/{{.Labels.org}}/{{.Labels.template}}/versions/{{.Labels.template_version}}" | ||
} | ||
]'::jsonb); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,11 @@ FROM templates t | |
WHERE tvp.desired_instances IS NOT NULL -- Consider only presets that have a prebuild configuration. | ||
AND (t.id = sqlc.narg('template_id')::uuid OR sqlc.narg('template_id') IS NULL); | ||
|
||
-- name: GetTemplatePresetsByID :one | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I missed that. |
||
SELECT * | ||
FROM template_version_presets | ||
WHERE id = $1; | ||
|
||
-- name: GetRunningPrebuiltWorkspaces :many | ||
SELECT | ||
p.id, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,9 @@ import ( | |
"golang.org/x/xerrors" | ||
|
||
"cdr.dev/slog" | ||
"github.com/coder/quartz" | ||
"github.com/coder/serpent" | ||
|
||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbauthz" | ||
|
@@ -48,8 +51,6 @@ import ( | |
"github.com/coder/coder/v2/coderd/util/syncmap" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/testutil" | ||
"github.com/coder/quartz" | ||
"github.com/coder/serpent" | ||
) | ||
|
||
// updateGoldenFiles is a flag that can be set to update golden files. | ||
|
@@ -1226,6 +1227,29 @@ func TestNotificationTemplates_Golden(t *testing.T) { | |
Labels: map[string]string{}, | ||
}, | ||
}, | ||
{ | ||
name: "TemplateWorkspaceResourceReplaced", | ||
id: notifications.TemplateWorkspaceResourceReplaced, | ||
payload: types.MessagePayload{ | ||
UserName: "Bobby", | ||
UserEmail: "[email protected]", | ||
UserUsername: "bobby", | ||
Labels: map[string]string{ | ||
"org": "cern", | ||
"workspace": "my-workspace", | ||
"workspace_build_num": "2", | ||
"template": "docker", | ||
"template_version": "angry_torvalds", | ||
"preset": "particle-accelerator", | ||
"claimant": "prebuilds-claimer", | ||
}, | ||
Data: map[string]any{ | ||
"replacements": map[string]string{ | ||
"docker_container[0]": "env, hostname", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// We must have a test case for every notification_template. This is enforced below: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on #17580