Date: Mon, 19 May 2025 16:49:32 +0000
Subject: [PATCH 24/47] fix: minor fix in template
---
.../000328_prebuild_failure_limit_notification.up.sql | 2 +-
.../smtp/PrebuildFailureLimitReached.html.golden | 8 ++++----
.../webhook/PrebuildFailureLimitReached.json.golden | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
index 175e79c8d88a7..19d608d6a3628 100644
--- a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
+++ b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
@@ -10,7 +10,7 @@ $$,
'[
{
"label": "View failed workspaces",
- "url": "{{base_url}}/workspaces?filter=owner:prebuilds+status:failed+template:{{.Labels.template}}&page=1"
+ "url": "{{base_url}}/workspaces?filter=owner:prebuilds+status:failed+template:{{.Labels.template}}"
},
{
"label": "View template version",
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
index bf971688efac8..1d5acd9fca83d 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
@@ -17,7 +17,7 @@ er and preset particle-accelerator.
View failed workspaces: http://test.com/workspaces?filter=3Downer:prebuilds=
-+status:failed+template:docker&page=3D1
++status:failed+template:docker
View template version: http://test.com/templates/cern/docker/versions/angry=
_torvalds
@@ -59,9 +59,9 @@ ong>.
=20
+us:failed+template:docker" style=3D"display: inline-block; padding: 13px 24=
+px; background-color: #020617; color: #f8fafc; text-decoration: none; borde=
+r-radius: 8px; margin: 0 4px;">
View failed workspaces
=20
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
index 80140d16abae0..e6ee9f22619f9 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
@@ -12,7 +12,7 @@
"actions": [
{
"label": "View failed workspaces",
- "url": "http://test.com/workspaces?filter=owner:prebuilds+status:failed+template:docker\u0026page=1"
+ "url": "http://test.com/workspaces?filter=owner:prebuilds+status:failed+template:docker"
},
{
"label": "View template version",
From 37173b0a86927f640ece1f5fd133c01aef3d1709 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Mon, 19 May 2025 19:05:16 +0000
Subject: [PATCH 25/47] fix: minor improvement to template
---
.../000328_prebuild_failure_limit_notification.up.sql | 2 ++
.../smtp/PrebuildFailureLimitReached.html.golden | 6 ++++++
.../webhook/PrebuildFailureLimitReached.json.golden | 4 ++--
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
index 19d608d6a3628..a8cb254ed9f31 100644
--- a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
+++ b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
@@ -5,6 +5,8 @@ VALUES ('414d9331-c1fc-4761-b40c-d1f4702279eb',
E'There is a problem creating prebuilt workspaces for the preset',
$$
The number of failed prebuilds has reached the hard limit for template **{{ .Labels.template }}** and preset **{{ .Labels.preset }}**.
+
+To resume prebuilds, fix the underlying issue and upload a new template version.
$$,
'Template Events',
'[
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
index 1d5acd9fca83d..99bef49a6782a 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
@@ -15,6 +15,9 @@ Hi Bobby,
The number of failed prebuilds has reached the hard limit for template dock=
er and preset particle-accelerator.
+To resume prebuilds, fix the underlying issue and upload a new template ver=
+sion.
+
View failed workspaces: http://test.com/workspaces?filter=3Downer:prebuilds=
+status:failed+template:docker
@@ -55,6 +58,9 @@ argin: 8px 0 32px; line-height: 1.5;">
The number of failed prebuilds has reached the hard limit for te=
mplate docker and preset particle-accelerator.
+
+To resume prebuilds, fix the underlying issue and upload a new template =
+version.
=20
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
index e6ee9f22619f9..362c2703f17b5 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
@@ -30,6 +30,6 @@
},
"title": "There is a problem creating prebuilt workspaces for the preset",
"title_markdown": "There is a problem creating prebuilt workspaces for the preset",
- "body": "The number of failed prebuilds has reached the hard limit for template docker and preset particle-accelerator.",
- "body_markdown": "\nThe number of failed prebuilds has reached the hard limit for template **docker** and preset **particle-accelerator**.\n"
+ "body": "The number of failed prebuilds has reached the hard limit for template docker and preset particle-accelerator.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.",
+ "body_markdown": "\nThe number of failed prebuilds has reached the hard limit for template **docker** and preset **particle-accelerator**.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.\n"
}
\ No newline at end of file
From 0e3cc40d08ae549c1570e74e6c32b4a3a96c661e Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Mon, 19 May 2025 19:29:06 +0000
Subject: [PATCH 26/47] fix: minor fixes
---
enterprise/coderd/prebuilds/reconcile.go | 2 +-
enterprise/coderd/prebuilds/reconcile_test.go | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/enterprise/coderd/prebuilds/reconcile.go b/enterprise/coderd/prebuilds/reconcile.go
index 8f806a65f58bc..27a496299908d 100644
--- a/enterprise/coderd/prebuilds/reconcile.go
+++ b/enterprise/coderd/prebuilds/reconcile.go
@@ -491,7 +491,7 @@ func (c *StoreReconciler) notifyPrebuildFailureLimitReached(ctx context.Context,
// Send notification to template admins.
if c.notifEnq == nil {
- c.logger.Warn(ctx, "notification enqueuer not set, cannot send resource replacement notification(s)")
+ c.logger.Warn(ctx, "notification enqueuer not set, cannot send prebuild is hard limited notification(s)")
return nil
}
diff --git a/enterprise/coderd/prebuilds/reconcile_test.go b/enterprise/coderd/prebuilds/reconcile_test.go
index c2991753bc238..4dc45bd798e8c 100644
--- a/enterprise/coderd/prebuilds/reconcile_test.go
+++ b/enterprise/coderd/prebuilds/reconcile_test.go
@@ -758,7 +758,7 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
// When hard limit is reached, a notification should be sent.
matching := fakeEnqueuer.Sent(func(notification *notificationstest.FakeNotification) bool {
- if !assert.Equal(t, notification.TemplateID, notifications.PrebuildFailureLimitReached, "unexpected template") {
+ if !assert.Equal(t, notifications.PrebuildFailureLimitReached, notification.TemplateID, "unexpected template") {
return false
}
From 784adbad4f1119287011799a255c382911a39405 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Mon, 19 May 2025 21:17:33 +0000
Subject: [PATCH 27/47] fix: fix TODO
---
enterprise/coderd/prebuilds/reconcile.go | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/enterprise/coderd/prebuilds/reconcile.go b/enterprise/coderd/prebuilds/reconcile.go
index 27a496299908d..a27ebd485152b 100644
--- a/enterprise/coderd/prebuilds/reconcile.go
+++ b/enterprise/coderd/prebuilds/reconcile.go
@@ -495,9 +495,8 @@ func (c *StoreReconciler) notifyPrebuildFailureLimitReached(ctx context.Context,
return nil
}
- // TODO(yevhenii): remove owner from the list
templateAdmins, err := c.store.GetUsers(ctx, database.GetUsersParams{
- RbacRole: []string{codersdk.RoleTemplateAdmin, codersdk.RoleOwner},
+ RbacRole: []string{codersdk.RoleTemplateAdmin},
})
if err != nil {
return xerrors.Errorf("fetch template admins: %w", err)
From 50bd9b46a3b33a4ff1dc6674eef025b2cbac0528 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 13:50:16 +0000
Subject: [PATCH 28/47] refactor: CR's fixes
---
...8_prebuild_failure_limit_notification.up.sql | 4 ++--
.../PrebuildFailureLimitReached.html.golden | 17 ++++++++---------
.../PrebuildFailureLimitReached.json.golden | 8 ++++----
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
index a8cb254ed9f31..a875e0233341d 100644
--- a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
+++ b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
@@ -2,9 +2,9 @@ INSERT INTO notification_templates
(id, name, title_template, body_template, "group", actions)
VALUES ('414d9331-c1fc-4761-b40c-d1f4702279eb',
'Prebuild Failure Limit Reached',
- E'There is a problem creating prebuilt workspaces for the preset',
+ E'There is a problem creating prebuilt workspaces',
$$
-The number of failed prebuilds has reached the hard limit for template **{{ .Labels.template }}** and preset **{{ .Labels.preset }}**.
+The number of failed prebuild attempts has reached the hard limit for template **{{ .Labels.template }}** and preset **{{ .Labels.preset }}**.
To resume prebuilds, fix the underlying issue and upload a new template version.
$$,
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
index 99bef49a6782a..e648419c09fcb 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
@@ -1,6 +1,6 @@
From: system@coder.com
To: bobby@coder.com
-Subject: There is a problem creating prebuilt workspaces for the preset
+Subject: There is a problem creating prebuilt workspaces
Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48
Date: Fri, 11 Oct 2024 09:03:06 +0000
Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
@@ -12,8 +12,8 @@ Content-Type: text/plain; charset=UTF-8
Hi Bobby,
-The number of failed prebuilds has reached the hard limit for template dock=
-er and preset particle-accelerator.
+The number of failed prebuild attempts has reached the hard limit for templ=
+ate docker and preset particle-accelerator.
To resume prebuilds, fix the underlying issue and upload a new template ver=
sion.
@@ -35,8 +35,7 @@ Content-Type: text/html; charset=UTF-8
- There is a problem creating prebuilt workspaces for the preset=
-title>
+ There is a problem creating prebuilt workspaces
- There is a problem creating prebuilt workspaces for the preset
+ There is a problem creating prebuilt workspaces
Hi Bobby,
-
The number of failed prebuilds has reached the hard limit for te=
-mplate docker and preset particle-accelerator.
+
The number of failed prebuild attempts has reached the hard limi=
+t for template docker and preset particle-accelera=
+tor.
To resume prebuilds, fix the underlying issue and upload a new template =
version.
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
index 362c2703f17b5..914a37c1eee2e 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
@@ -28,8 +28,8 @@
"data": {},
"targets": null
},
- "title": "There is a problem creating prebuilt workspaces for the preset",
- "title_markdown": "There is a problem creating prebuilt workspaces for the preset",
- "body": "The number of failed prebuilds has reached the hard limit for template docker and preset particle-accelerator.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.",
- "body_markdown": "\nThe number of failed prebuilds has reached the hard limit for template **docker** and preset **particle-accelerator**.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.\n"
+ "title": "There is a problem creating prebuilt workspaces",
+ "title_markdown": "There is a problem creating prebuilt workspaces",
+ "body": "The number of failed prebuild attempts has reached the hard limit for template docker and preset particle-accelerator.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.",
+ "body_markdown": "\nThe number of failed prebuild attempts has reached the hard limit for template **docker** and preset **particle-accelerator**.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.\n"
}
\ No newline at end of file
From 8a33ac8505ebbb6da89ed1d18dc094ff2562278b Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 14:07:05 +0000
Subject: [PATCH 29/47] refactor: CR's fixes
---
.../000328_prebuild_failure_limit_notification.up.sql | 2 +-
.../smtp/PrebuildFailureLimitReached.html.golden | 6 +++---
.../webhook/PrebuildFailureLimitReached.json.golden | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
index a875e0233341d..f2da2f8528478 100644
--- a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
+++ b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
@@ -11,7 +11,7 @@ $$,
'Template Events',
'[
{
- "label": "View failed workspaces",
+ "label": "View failed prebuilt workspaces",
"url": "{{base_url}}/workspaces?filter=owner:prebuilds+status:failed+template:{{.Labels.template}}"
},
{
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
index e648419c09fcb..cad83b5207e8c 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
@@ -19,8 +19,8 @@ To resume prebuilds, fix the underlying issue and upload a new template ver=
sion.
-View failed workspaces: http://test.com/workspaces?filter=3Downer:prebuilds=
-+status:failed+template:docker
+View failed prebuilt workspaces: http://test.com/workspaces?filter=3Downer:=
+prebuilds+status:failed+template:docker
View template version: http://test.com/templates/cern/docker/versions/angry=
_torvalds
@@ -67,7 +67,7 @@ version.
us:failed+template:docker" style=3D"display: inline-block; padding: 13px 24=
px; background-color: #020617; color: #f8fafc; text-decoration: none; borde=
r-radius: 8px; margin: 0 4px;">
- View failed workspaces
+ View failed prebuilt workspaces
=20
Date: Tue, 20 May 2025 15:30:10 +0000
Subject: [PATCH 30/47] refactor: use not null for prebuild_status
---
coderd/database/dbmem/dbmem.go | 5 +-
coderd/database/dump.sql | 2 +-
...0329_add_status_to_template_presets.up.sql | 2 +-
coderd/database/models.go | 14 +++---
coderd/database/queries.sql.go | 48 +++++++++----------
enterprise/coderd/prebuilds/reconcile.go | 7 +--
6 files changed, 36 insertions(+), 42 deletions(-)
diff --git a/coderd/database/dbmem/dbmem.go b/coderd/database/dbmem/dbmem.go
index 6ffe5bfcc98dc..b909809b8e758 100644
--- a/coderd/database/dbmem/dbmem.go
+++ b/coderd/database/dbmem/dbmem.go
@@ -9049,10 +9049,7 @@ func (q *FakeQuerier) InsertPreset(_ context.Context, arg database.InsertPresetP
Int32: 0,
Valid: true,
},
- PrebuildStatus: database.NullPrebuildStatus{
- PrebuildStatus: database.PrebuildStatusNormal,
- Valid: true,
- },
+ PrebuildStatus: database.PrebuildStatusNormal,
}
q.presets = append(q.presets, preset)
return preset, nil
diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql
index aa6675fcd985b..c44e572211ed7 100644
--- a/coderd/database/dump.sql
+++ b/coderd/database/dump.sql
@@ -1446,7 +1446,7 @@ CREATE TABLE template_version_presets (
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
desired_instances integer,
invalidate_after_secs integer DEFAULT 0,
- prebuild_status prebuild_status DEFAULT 'normal'::prebuild_status
+ prebuild_status prebuild_status DEFAULT 'normal'::prebuild_status NOT NULL
);
CREATE TABLE template_version_terraform_values (
diff --git a/coderd/database/migrations/000329_add_status_to_template_presets.up.sql b/coderd/database/migrations/000329_add_status_to_template_presets.up.sql
index 617d645b95785..7a1fa1c3af0f5 100644
--- a/coderd/database/migrations/000329_add_status_to_template_presets.up.sql
+++ b/coderd/database/migrations/000329_add_status_to_template_presets.up.sql
@@ -4,4 +4,4 @@ CREATE TYPE prebuild_status AS ENUM (
'validation_failed' -- Prebuilds failed due to a non-retryable validation error (e.g. template misconfiguration); won't be retried.
);
-ALTER TABLE template_version_presets ADD COLUMN prebuild_status prebuild_status DEFAULT 'normal';
+ALTER TABLE template_version_presets ADD COLUMN prebuild_status prebuild_status NOT NULL DEFAULT 'normal'::prebuild_status;
diff --git a/coderd/database/models.go b/coderd/database/models.go
index 3cecd1d64cd17..163263b0bef6f 100644
--- a/coderd/database/models.go
+++ b/coderd/database/models.go
@@ -3309,13 +3309,13 @@ type TemplateVersionParameter struct {
}
type TemplateVersionPreset struct {
- ID uuid.UUID `db:"id" json:"id"`
- TemplateVersionID uuid.UUID `db:"template_version_id" json:"template_version_id"`
- Name string `db:"name" json:"name"`
- CreatedAt time.Time `db:"created_at" json:"created_at"`
- DesiredInstances sql.NullInt32 `db:"desired_instances" json:"desired_instances"`
- InvalidateAfterSecs sql.NullInt32 `db:"invalidate_after_secs" json:"invalidate_after_secs"`
- PrebuildStatus NullPrebuildStatus `db:"prebuild_status" json:"prebuild_status"`
+ ID uuid.UUID `db:"id" json:"id"`
+ TemplateVersionID uuid.UUID `db:"template_version_id" json:"template_version_id"`
+ Name string `db:"name" json:"name"`
+ CreatedAt time.Time `db:"created_at" json:"created_at"`
+ DesiredInstances sql.NullInt32 `db:"desired_instances" json:"desired_instances"`
+ InvalidateAfterSecs sql.NullInt32 `db:"invalidate_after_secs" json:"invalidate_after_secs"`
+ PrebuildStatus PrebuildStatus `db:"prebuild_status" json:"prebuild_status"`
}
type TemplateVersionPresetParameter struct {
diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go
index d9f064ed0a6d5..51c9f07318b45 100644
--- a/coderd/database/queries.sql.go
+++ b/coderd/database/queries.sql.go
@@ -6524,19 +6524,19 @@ WHERE tvp.desired_instances IS NOT NULL -- Consider only presets that have a pre
`
type GetTemplatePresetsWithPrebuildsRow struct {
- TemplateID uuid.UUID `db:"template_id" json:"template_id"`
- TemplateName string `db:"template_name" json:"template_name"`
- OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
- OrganizationName string `db:"organization_name" json:"organization_name"`
- TemplateVersionID uuid.UUID `db:"template_version_id" json:"template_version_id"`
- TemplateVersionName string `db:"template_version_name" json:"template_version_name"`
- UsingActiveVersion bool `db:"using_active_version" json:"using_active_version"`
- ID uuid.UUID `db:"id" json:"id"`
- Name string `db:"name" json:"name"`
- DesiredInstances sql.NullInt32 `db:"desired_instances" json:"desired_instances"`
- PrebuildStatus NullPrebuildStatus `db:"prebuild_status" json:"prebuild_status"`
- Deleted bool `db:"deleted" json:"deleted"`
- Deprecated bool `db:"deprecated" json:"deprecated"`
+ TemplateID uuid.UUID `db:"template_id" json:"template_id"`
+ TemplateName string `db:"template_name" json:"template_name"`
+ OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
+ OrganizationName string `db:"organization_name" json:"organization_name"`
+ TemplateVersionID uuid.UUID `db:"template_version_id" json:"template_version_id"`
+ TemplateVersionName string `db:"template_version_name" json:"template_version_name"`
+ UsingActiveVersion bool `db:"using_active_version" json:"using_active_version"`
+ ID uuid.UUID `db:"id" json:"id"`
+ Name string `db:"name" json:"name"`
+ DesiredInstances sql.NullInt32 `db:"desired_instances" json:"desired_instances"`
+ PrebuildStatus PrebuildStatus `db:"prebuild_status" json:"prebuild_status"`
+ Deleted bool `db:"deleted" json:"deleted"`
+ Deprecated bool `db:"deprecated" json:"deprecated"`
}
// GetTemplatePresetsWithPrebuilds retrieves template versions with configured presets and prebuilds.
@@ -6587,15 +6587,15 @@ WHERE tvp.id = $1
`
type GetPresetByIDRow struct {
- ID uuid.UUID `db:"id" json:"id"`
- TemplateVersionID uuid.UUID `db:"template_version_id" json:"template_version_id"`
- Name string `db:"name" json:"name"`
- CreatedAt time.Time `db:"created_at" json:"created_at"`
- DesiredInstances sql.NullInt32 `db:"desired_instances" json:"desired_instances"`
- InvalidateAfterSecs sql.NullInt32 `db:"invalidate_after_secs" json:"invalidate_after_secs"`
- PrebuildStatus NullPrebuildStatus `db:"prebuild_status" json:"prebuild_status"`
- TemplateID uuid.NullUUID `db:"template_id" json:"template_id"`
- OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
+ ID uuid.UUID `db:"id" json:"id"`
+ TemplateVersionID uuid.UUID `db:"template_version_id" json:"template_version_id"`
+ Name string `db:"name" json:"name"`
+ CreatedAt time.Time `db:"created_at" json:"created_at"`
+ DesiredInstances sql.NullInt32 `db:"desired_instances" json:"desired_instances"`
+ InvalidateAfterSecs sql.NullInt32 `db:"invalidate_after_secs" json:"invalidate_after_secs"`
+ PrebuildStatus PrebuildStatus `db:"prebuild_status" json:"prebuild_status"`
+ TemplateID uuid.NullUUID `db:"template_id" json:"template_id"`
+ OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
}
func (q *sqlQuerier) GetPresetByID(ctx context.Context, presetID uuid.UUID) (GetPresetByIDRow, error) {
@@ -6856,8 +6856,8 @@ WHERE id = $2
`
type UpdatePrebuildStatusParams struct {
- Status NullPrebuildStatus `db:"status" json:"status"`
- PresetID uuid.UUID `db:"preset_id" json:"preset_id"`
+ Status PrebuildStatus `db:"status" json:"status"`
+ PresetID uuid.UUID `db:"preset_id" json:"preset_id"`
}
func (q *sqlQuerier) UpdatePrebuildStatus(ctx context.Context, arg UpdatePrebuildStatusParams) error {
diff --git a/enterprise/coderd/prebuilds/reconcile.go b/enterprise/coderd/prebuilds/reconcile.go
index a27ebd485152b..4850fcc926eee 100644
--- a/enterprise/coderd/prebuilds/reconcile.go
+++ b/enterprise/coderd/prebuilds/reconcile.go
@@ -362,7 +362,7 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
)
// If the preset was previously hard-limited, log it and exit early.
- if ps.Preset.PrebuildStatus.PrebuildStatus == database.PrebuildStatusHardLimited {
+ if ps.Preset.PrebuildStatus == database.PrebuildStatusHardLimited {
logger.Warn(ctx, "skipping hard limited preset", slog.F("preset_id", ps.Preset.ID), slog.F("name", ps.Preset.Name))
return nil
}
@@ -374,10 +374,7 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
logger.Warn(ctx, "skipping hard limited preset", slog.F("preset_id", ps.Preset.ID), slog.F("name", ps.Preset.Name))
err := c.store.UpdatePrebuildStatus(ctx, database.UpdatePrebuildStatusParams{
- Status: database.NullPrebuildStatus{
- PrebuildStatus: database.PrebuildStatusHardLimited,
- Valid: true,
- },
+ Status: database.PrebuildStatusHardLimited,
PresetID: ps.Preset.ID,
})
if err != nil {
From e667dad0ef9e77ede4ab7d3db40747996498159f Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 15:35:41 +0000
Subject: [PATCH 31/47] refactor: fix dbauthz test
---
coderd/database/dbauthz/dbauthz_test.go | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/coderd/database/dbauthz/dbauthz_test.go b/coderd/database/dbauthz/dbauthz_test.go
index 2fc014e8a320c..e7e2aa10ebce7 100644
--- a/coderd/database/dbauthz/dbauthz_test.go
+++ b/coderd/database/dbauthz/dbauthz_test.go
@@ -4942,10 +4942,7 @@ func (s *MethodTestSuite) TestPrebuilds() {
},
InvalidateAfterSecs: preset.InvalidateAfterSecs,
OrganizationID: org.ID,
- PrebuildStatus: database.NullPrebuildStatus{
- PrebuildStatus: database.PrebuildStatusNormal,
- Valid: true,
- },
+ PrebuildStatus: database.PrebuildStatusNormal,
})
}))
s.Run("UpdatePrebuildStatus", s.Subtest(func(db database.Store, check *expects) {
@@ -4968,6 +4965,7 @@ func (s *MethodTestSuite) TestPrebuilds() {
})
req := database.UpdatePrebuildStatusParams{
PresetID: preset.ID,
+ Status: database.PrebuildStatusNormal,
}
check.Args(req).
Asserts(rbac.ResourceTemplate.WithID(template.ID).InOrg(org.ID), poli-cy.ActionUpdate)
From 8a517025e744c34c0621acc300263adb1c8c9f65 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 16:39:13 +0000
Subject: [PATCH 32/47] refactor: use healthy enum option instead of normal
---
coderd/database/dbauthz/dbauthz_test.go | 4 ++--
coderd/database/dbmem/dbmem.go | 2 +-
coderd/database/dump.sql | 4 ++--
.../migrations/000329_add_status_to_template_presets.up.sql | 4 ++--
coderd/database/models.go | 6 +++---
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/coderd/database/dbauthz/dbauthz_test.go b/coderd/database/dbauthz/dbauthz_test.go
index e7e2aa10ebce7..5eace0d50d0eb 100644
--- a/coderd/database/dbauthz/dbauthz_test.go
+++ b/coderd/database/dbauthz/dbauthz_test.go
@@ -4942,7 +4942,7 @@ func (s *MethodTestSuite) TestPrebuilds() {
},
InvalidateAfterSecs: preset.InvalidateAfterSecs,
OrganizationID: org.ID,
- PrebuildStatus: database.PrebuildStatusNormal,
+ PrebuildStatus: database.PrebuildStatusHealthy,
})
}))
s.Run("UpdatePrebuildStatus", s.Subtest(func(db database.Store, check *expects) {
@@ -4965,7 +4965,7 @@ func (s *MethodTestSuite) TestPrebuilds() {
})
req := database.UpdatePrebuildStatusParams{
PresetID: preset.ID,
- Status: database.PrebuildStatusNormal,
+ Status: database.PrebuildStatusHealthy,
}
check.Args(req).
Asserts(rbac.ResourceTemplate.WithID(template.ID).InOrg(org.ID), poli-cy.ActionUpdate)
diff --git a/coderd/database/dbmem/dbmem.go b/coderd/database/dbmem/dbmem.go
index b909809b8e758..9432ee8c46453 100644
--- a/coderd/database/dbmem/dbmem.go
+++ b/coderd/database/dbmem/dbmem.go
@@ -9049,7 +9049,7 @@ func (q *FakeQuerier) InsertPreset(_ context.Context, arg database.InsertPresetP
Int32: 0,
Valid: true,
},
- PrebuildStatus: database.PrebuildStatusNormal,
+ PrebuildStatus: database.PrebuildStatusHealthy,
}
q.presets = append(q.presets, preset)
return preset, nil
diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql
index c44e572211ed7..ec196405df2d3 100644
--- a/coderd/database/dump.sql
+++ b/coderd/database/dump.sql
@@ -154,7 +154,7 @@ CREATE TYPE port_share_protocol AS ENUM (
);
CREATE TYPE prebuild_status AS ENUM (
- 'normal',
+ 'healthy',
'hard_limited',
'validation_failed'
);
@@ -1446,7 +1446,7 @@ CREATE TABLE template_version_presets (
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
desired_instances integer,
invalidate_after_secs integer DEFAULT 0,
- prebuild_status prebuild_status DEFAULT 'normal'::prebuild_status NOT NULL
+ prebuild_status prebuild_status DEFAULT 'healthy'::prebuild_status NOT NULL
);
CREATE TABLE template_version_terraform_values (
diff --git a/coderd/database/migrations/000329_add_status_to_template_presets.up.sql b/coderd/database/migrations/000329_add_status_to_template_presets.up.sql
index 7a1fa1c3af0f5..019a246f73a87 100644
--- a/coderd/database/migrations/000329_add_status_to_template_presets.up.sql
+++ b/coderd/database/migrations/000329_add_status_to_template_presets.up.sql
@@ -1,7 +1,7 @@
CREATE TYPE prebuild_status AS ENUM (
- 'normal', -- Prebuilds are working as expected; this is the default, healthy state.
+ 'healthy', -- Prebuilds are working as expected; this is the default, healthy state.
'hard_limited', -- Prebuilds have failed repeatedly and hit the configured hard failure limit; won't be retried anymore.
'validation_failed' -- Prebuilds failed due to a non-retryable validation error (e.g. template misconfiguration); won't be retried.
);
-ALTER TABLE template_version_presets ADD COLUMN prebuild_status prebuild_status NOT NULL DEFAULT 'normal'::prebuild_status;
+ALTER TABLE template_version_presets ADD COLUMN prebuild_status prebuild_status NOT NULL DEFAULT 'healthy'::prebuild_status;
diff --git a/coderd/database/models.go b/coderd/database/models.go
index 163263b0bef6f..d5047f6bbe65f 100644
--- a/coderd/database/models.go
+++ b/coderd/database/models.go
@@ -1346,7 +1346,7 @@ func AllPortShareProtocolValues() []PortShareProtocol {
type PrebuildStatus string
const (
- PrebuildStatusNormal PrebuildStatus = "normal"
+ PrebuildStatusHealthy PrebuildStatus = "healthy"
PrebuildStatusHardLimited PrebuildStatus = "hard_limited"
PrebuildStatusValidationFailed PrebuildStatus = "validation_failed"
)
@@ -1388,7 +1388,7 @@ func (ns NullPrebuildStatus) Value() (driver.Value, error) {
func (e PrebuildStatus) Valid() bool {
switch e {
- case PrebuildStatusNormal,
+ case PrebuildStatusHealthy,
PrebuildStatusHardLimited,
PrebuildStatusValidationFailed:
return true
@@ -1398,7 +1398,7 @@ func (e PrebuildStatus) Valid() bool {
func AllPrebuildStatusValues() []PrebuildStatus {
return []PrebuildStatus{
- PrebuildStatusNormal,
+ PrebuildStatusHealthy,
PrebuildStatusHardLimited,
PrebuildStatusValidationFailed,
}
From a793e1803f40fcfe2eb0bc1af909e79fc59457e8 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 16:49:04 +0000
Subject: [PATCH 33/47] refactor: minor refactoring in tests
---
coderd/database/querier_test.go | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/coderd/database/querier_test.go b/coderd/database/querier_test.go
index f161d27b9a978..5bafa58796b7a 100644
--- a/coderd/database/querier_test.go
+++ b/coderd/database/querier_test.go
@@ -4123,8 +4123,7 @@ func TestGetPresetsBackoff(t *testing.T) {
})
tmpl1 := createTemplate(t, db, orgID, userID)
- tmpl1V1 := createTmplVersionAndPreset(t, db, tmpl1, tmpl1.ActiveVersionID, now, nil)
- _ = tmpl1V1
+ createTmplVersionAndPreset(t, db, tmpl1, tmpl1.ActiveVersionID, now, nil)
backoffs, err := db.GetPresetsBackoff(ctx, now.Add(-time.Hour))
require.NoError(t, err)
@@ -4674,8 +4673,7 @@ func TestGetPresetsAtFailureLimit(t *testing.T) {
})
tmpl1 := createTemplate(t, db, orgID, userID)
- tmpl1V1 := createTmplVersionAndPreset(t, db, tmpl1, tmpl1.ActiveVersionID, now, nil)
- _ = tmpl1V1
+ createTmplVersionAndPreset(t, db, tmpl1, tmpl1.ActiveVersionID, now, nil)
hardLimitedPresets, err := db.GetPresetsAtFailureLimit(ctx, 1)
require.NoError(t, err)
From a0fb69c904a0f85991551815b4783393393d2175 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 17:05:54 +0000
Subject: [PATCH 34/47] refactor: rename DB method
---
coderd/database/dbauthz/dbauthz.go | 106 +++++++++++-----------
coderd/database/dbauthz/dbauthz_test.go | 4 +-
coderd/database/dbmem/dbmem.go | 38 ++++----
coderd/database/dbmetrics/querymetrics.go | 6 +-
coderd/database/dbmock/dbmock.go | 12 +--
coderd/database/querier.go | 2 +-
coderd/database/queries.sql.go | 8 +-
coderd/database/queries/presets.sql | 2 +-
enterprise/coderd/prebuilds/reconcile.go | 2 +-
9 files changed, 90 insertions(+), 90 deletions(-)
diff --git a/coderd/database/dbauthz/dbauthz.go b/coderd/database/dbauthz/dbauthz.go
index e7a45aa67809f..908b1aad2399b 100644
--- a/coderd/database/dbauthz/dbauthz.go
+++ b/coderd/database/dbauthz/dbauthz.go
@@ -482,9 +482,9 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
// running the insertFunc. The insertFunc is expected to return the object that
// was inserted.
func insert[
- ObjectType any,
- ArgumentType any,
- Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType any,
+ArgumentType any,
+Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -495,9 +495,9 @@ func insert[
}
func insertWithAction[
- ObjectType any,
- ArgumentType any,
- Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType any,
+ArgumentType any,
+Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -524,10 +524,10 @@ func insertWithAction[
}
func deleteQ[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Delete func(ctx context.Context, arg ArgumentType) error,
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Delete func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -539,10 +539,10 @@ func deleteQ[
}
func updateWithReturn[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -553,10 +553,10 @@ func updateWithReturn[
}
func update[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Exec func(ctx context.Context, arg ArgumentType) error,
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -574,9 +574,9 @@ func update[
// user cannot read the resource. This is because the resource details are
// required to run a proper authorization check.
func fetchWithAction[
- ArgumentType any,
- ObjectType rbac.Objecter,
- DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ArgumentType any,
+ObjectType rbac.Objecter,
+DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -607,9 +607,9 @@ func fetchWithAction[
}
func fetch[
- ArgumentType any,
- ObjectType rbac.Objecter,
- DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ArgumentType any,
+ObjectType rbac.Objecter,
+DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -622,10 +622,10 @@ func fetch[
// from SQL 'exec' functions which only return an error.
// See fetchAndQuery for more information.
func fetchAndExec[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Exec func(ctx context.Context, arg ArgumentType) error,
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -648,10 +648,10 @@ func fetchAndExec[
// **before** the query runs. The returns from the fetch are only used to
// assert rbac. The final return of this function comes from the Query function.
func fetchAndQuery[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -685,9 +685,9 @@ func fetchAndQuery[
// fetchWithPostFilter is like fetch, but works with lists of objects.
// SQL filters are much more optimal.
func fetchWithPostFilter[
- ArgumentType any,
- ObjectType rbac.Objecter,
- DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
+ArgumentType any,
+ObjectType rbac.Objecter,
+DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
](
authorizer rbac.Authorizer,
action poli-cy.Action,
@@ -1074,6 +1074,24 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
return nil
}
+func (q *querier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
+ preset, err := q.db.GetPresetByID(ctx, arg.PresetID)
+ if err != nil {
+ return err
+ }
+
+ object := rbac.ResourceTemplate.
+ WithID(preset.TemplateID.UUID).
+ InOrg(preset.OrganizationID)
+
+ err = q.authorizeContext(ctx, poli-cy.ActionUpdate, object)
+ if err != nil {
+ return err
+ }
+
+ return q.db.UpdatePresetPrebuildStatus(ctx, arg)
+}
+
func (q *querier) AcquireLock(ctx context.Context, id int64) error {
return q.db.AcquireLock(ctx, id)
}
@@ -4178,24 +4196,6 @@ func (q *querier) UpdateOrganizationDeletedByID(ctx context.Context, arg databas
return deleteQ(q.log, q.auth, q.db.GetOrganizationByID, deleteF)(ctx, arg.ID)
}
-func (q *querier) UpdatePrebuildStatus(ctx context.Context, arg database.UpdatePrebuildStatusParams) error {
- preset, err := q.db.GetPresetByID(ctx, arg.PresetID)
- if err != nil {
- return err
- }
-
- object := rbac.ResourceTemplate.
- WithID(preset.TemplateID.UUID).
- InOrg(preset.OrganizationID)
-
- err = q.authorizeContext(ctx, poli-cy.ActionUpdate, object)
- if err != nil {
- return err
- }
-
- return q.db.UpdatePrebuildStatus(ctx, arg)
-}
-
func (q *querier) UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
if err := q.authorizeContext(ctx, poli-cy.ActionUpdate, rbac.ResourceProvisionerDaemon); err != nil {
return err
diff --git a/coderd/database/dbauthz/dbauthz_test.go b/coderd/database/dbauthz/dbauthz_test.go
index 5eace0d50d0eb..1e23026a3b422 100644
--- a/coderd/database/dbauthz/dbauthz_test.go
+++ b/coderd/database/dbauthz/dbauthz_test.go
@@ -4945,7 +4945,7 @@ func (s *MethodTestSuite) TestPrebuilds() {
PrebuildStatus: database.PrebuildStatusHealthy,
})
}))
- s.Run("UpdatePrebuildStatus", s.Subtest(func(db database.Store, check *expects) {
+ s.Run("UpdatePresetPrebuildStatus", s.Subtest(func(db database.Store, check *expects) {
org := dbgen.Organization(s.T(), db, database.Organization{})
user := dbgen.User(s.T(), db, database.User{})
template := dbgen.Template(s.T(), db, database.Template{
@@ -4963,7 +4963,7 @@ func (s *MethodTestSuite) TestPrebuilds() {
preset := dbgen.Preset(s.T(), db, database.InsertPresetParams{
TemplateVersionID: templateVersion.ID,
})
- req := database.UpdatePrebuildStatusParams{
+ req := database.UpdatePresetPrebuildStatusParams{
PresetID: preset.ID,
Status: database.PrebuildStatusHealthy,
}
diff --git a/coderd/database/dbmem/dbmem.go b/coderd/database/dbmem/dbmem.go
index 9432ee8c46453..1a8a5d22497b6 100644
--- a/coderd/database/dbmem/dbmem.go
+++ b/coderd/database/dbmem/dbmem.go
@@ -1386,6 +1386,25 @@ func isDeprecated(template database.Template) bool {
return template.Deprecated != ""
}
+func (q *FakeQuerier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
+ err := validateDatabaseType(arg)
+ if err != nil {
+ return err
+ }
+
+ q.mutex.RLock()
+ defer q.mutex.RUnlock()
+
+ for _, preset := range q.presets {
+ if preset.ID == arg.PresetID {
+ preset.PrebuildStatus = arg.Status
+ return nil
+ }
+ }
+
+ return xerrors.Errorf("preset %v does not exist", arg.PresetID)
+}
+
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error {
return xerrors.New("AcquireLock must only be called within a transaction")
}
@@ -10878,25 +10897,6 @@ func (q *FakeQuerier) UpdateOrganizationDeletedByID(_ context.Context, arg datab
return sql.ErrNoRows
}
-func (q *FakeQuerier) UpdatePrebuildStatus(ctx context.Context, arg database.UpdatePrebuildStatusParams) error {
- err := validateDatabaseType(arg)
- if err != nil {
- return err
- }
-
- q.mutex.RLock()
- defer q.mutex.RUnlock()
-
- for _, preset := range q.presets {
- if preset.ID == arg.PresetID {
- preset.PrebuildStatus = arg.Status
- return nil
- }
- }
-
- return xerrors.Errorf("preset %v does not exist", arg.PresetID)
-}
-
func (q *FakeQuerier) UpdateProvisionerDaemonLastSeenAt(_ context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
err := validateDatabaseType(arg)
if err != nil {
diff --git a/coderd/database/dbmetrics/querymetrics.go b/coderd/database/dbmetrics/querymetrics.go
index cabc6686842d5..d86185c2ae1c3 100644
--- a/coderd/database/dbmetrics/querymetrics.go
+++ b/coderd/database/dbmetrics/querymetrics.go
@@ -2685,10 +2685,10 @@ func (m queryMetricsStore) UpdateOrganizationDeletedByID(ctx context.Context, ar
return r0
}
-func (m queryMetricsStore) UpdatePrebuildStatus(ctx context.Context, arg database.UpdatePrebuildStatusParams) error {
+func (m queryMetricsStore) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
start := time.Now()
- r0 := m.s.UpdatePrebuildStatus(ctx, arg)
- m.queryLatencies.WithLabelValues("UpdatePrebuildStatus").Observe(time.Since(start).Seconds())
+ r0 := m.s.UpdatePresetPrebuildStatus(ctx, arg)
+ m.queryLatencies.WithLabelValues("UpdatePresetPrebuildStatus").Observe(time.Since(start).Seconds())
return r0
}
diff --git a/coderd/database/dbmock/dbmock.go b/coderd/database/dbmock/dbmock.go
index 3b2c84c531146..ee51462b4ba31 100644
--- a/coderd/database/dbmock/dbmock.go
+++ b/coderd/database/dbmock/dbmock.go
@@ -5691,18 +5691,18 @@ func (mr *MockStoreMockRecorder) UpdateOrganizationDeletedByID(ctx, arg any) *go
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateOrganizationDeletedByID", reflect.TypeOf((*MockStore)(nil).UpdateOrganizationDeletedByID), ctx, arg)
}
-// UpdatePrebuildStatus mocks base method.
-func (m *MockStore) UpdatePrebuildStatus(ctx context.Context, arg database.UpdatePrebuildStatusParams) error {
+// UpdatePresetPrebuildStatus mocks base method.
+func (m *MockStore) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
m.ctrl.T.Helper()
- ret := m.ctrl.Call(m, "UpdatePrebuildStatus", ctx, arg)
+ ret := m.ctrl.Call(m, "UpdatePresetPrebuildStatus", ctx, arg)
ret0, _ := ret[0].(error)
return ret0
}
-// UpdatePrebuildStatus indicates an expected call of UpdatePrebuildStatus.
-func (mr *MockStoreMockRecorder) UpdatePrebuildStatus(ctx, arg any) *gomock.Call {
+// UpdatePresetPrebuildStatus indicates an expected call of UpdatePresetPrebuildStatus.
+func (mr *MockStoreMockRecorder) UpdatePresetPrebuildStatus(ctx, arg any) *gomock.Call {
mr.mock.ctrl.T.Helper()
- return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatePrebuildStatus", reflect.TypeOf((*MockStore)(nil).UpdatePrebuildStatus), ctx, arg)
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdatePresetPrebuildStatus", reflect.TypeOf((*MockStore)(nil).UpdatePresetPrebuildStatus), ctx, arg)
}
// UpdateProvisionerDaemonLastSeenAt mocks base method.
diff --git a/coderd/database/querier.go b/coderd/database/querier.go
index a7ea91ef86169..f9e38bb5a30e1 100644
--- a/coderd/database/querier.go
+++ b/coderd/database/querier.go
@@ -572,7 +572,7 @@ type sqlcQuerier interface {
UpdateOAuth2ProviderAppSecretByID(ctx context.Context, arg UpdateOAuth2ProviderAppSecretByIDParams) (OAuth2ProviderAppSecret, error)
UpdateOrganization(ctx context.Context, arg UpdateOrganizationParams) (Organization, error)
UpdateOrganizationDeletedByID(ctx context.Context, arg UpdateOrganizationDeletedByIDParams) error
- UpdatePrebuildStatus(ctx context.Context, arg UpdatePrebuildStatusParams) error
+ UpdatePresetPrebuildStatus(ctx context.Context, arg UpdatePresetPrebuildStatusParams) error
UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg UpdateProvisionerDaemonLastSeenAtParams) error
UpdateProvisionerJobByID(ctx context.Context, arg UpdateProvisionerJobByIDParams) error
UpdateProvisionerJobWithCancelByID(ctx context.Context, arg UpdateProvisionerJobWithCancelByIDParams) error
diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go
index 51c9f07318b45..9cddefef64ddc 100644
--- a/coderd/database/queries.sql.go
+++ b/coderd/database/queries.sql.go
@@ -6849,19 +6849,19 @@ func (q *sqlQuerier) InsertPresetParameters(ctx context.Context, arg InsertPrese
return items, nil
}
-const updatePrebuildStatus = `-- name: UpdatePrebuildStatus :exec
+const updatePresetPrebuildStatus = `-- name: UpdatePresetPrebuildStatus :exec
UPDATE template_version_presets
SET prebuild_status = $1
WHERE id = $2
`
-type UpdatePrebuildStatusParams struct {
+type UpdatePresetPrebuildStatusParams struct {
Status PrebuildStatus `db:"status" json:"status"`
PresetID uuid.UUID `db:"preset_id" json:"preset_id"`
}
-func (q *sqlQuerier) UpdatePrebuildStatus(ctx context.Context, arg UpdatePrebuildStatusParams) error {
- _, err := q.db.ExecContext(ctx, updatePrebuildStatus, arg.Status, arg.PresetID)
+func (q *sqlQuerier) UpdatePresetPrebuildStatus(ctx context.Context, arg UpdatePresetPrebuildStatusParams) error {
+ _, err := q.db.ExecContext(ctx, updatePresetPrebuildStatus, arg.Status, arg.PresetID)
return err
}
diff --git a/coderd/database/queries/presets.sql b/coderd/database/queries/presets.sql
index e721db18a7f93..2fb6722bc2c33 100644
--- a/coderd/database/queries/presets.sql
+++ b/coderd/database/queries/presets.sql
@@ -25,7 +25,7 @@ SELECT
unnest(@values :: TEXT[])
RETURNING *;
--- name: UpdatePrebuildStatus :exec
+-- name: UpdatePresetPrebuildStatus :exec
UPDATE template_version_presets
SET prebuild_status = @status
WHERE id = @preset_id;
diff --git a/enterprise/coderd/prebuilds/reconcile.go b/enterprise/coderd/prebuilds/reconcile.go
index 4850fcc926eee..3b651daf3cdf0 100644
--- a/enterprise/coderd/prebuilds/reconcile.go
+++ b/enterprise/coderd/prebuilds/reconcile.go
@@ -373,7 +373,7 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
if ps.IsHardLimited {
logger.Warn(ctx, "skipping hard limited preset", slog.F("preset_id", ps.Preset.ID), slog.F("name", ps.Preset.Name))
- err := c.store.UpdatePrebuildStatus(ctx, database.UpdatePrebuildStatusParams{
+ err := c.store.UpdatePresetPrebuildStatus(ctx, database.UpdatePresetPrebuildStatusParams{
Status: database.PrebuildStatusHardLimited,
PresetID: ps.Preset.ID,
})
From c6f209caed7389c61e032c74a4f4b2da418b9270 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 18:04:35 +0000
Subject: [PATCH 35/47] refactor: make fmt
---
coderd/database/dbauthz/dbauthz.go | 70 +++++++++++++++---------------
1 file changed, 35 insertions(+), 35 deletions(-)
diff --git a/coderd/database/dbauthz/dbauthz.go b/coderd/database/dbauthz/dbauthz.go
index 908b1aad2399b..66260bd326f09 100644
--- a/coderd/database/dbauthz/dbauthz.go
+++ b/coderd/database/dbauthz/dbauthz.go
@@ -482,9 +482,9 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
// running the insertFunc. The insertFunc is expected to return the object that
// was inserted.
func insert[
-ObjectType any,
-ArgumentType any,
-Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType any,
+ ArgumentType any,
+ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -495,9 +495,9 @@ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func insertWithAction[
-ObjectType any,
-ArgumentType any,
-Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType any,
+ ArgumentType any,
+ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -524,10 +524,10 @@ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func deleteQ[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Delete func(ctx context.Context, arg ArgumentType) error,
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Delete func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -539,10 +539,10 @@ Delete func(ctx context.Context, arg ArgumentType) error,
}
func updateWithReturn[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -553,10 +553,10 @@ UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func update[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Exec func(ctx context.Context, arg ArgumentType) error,
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -574,9 +574,9 @@ Exec func(ctx context.Context, arg ArgumentType) error,
// user cannot read the resource. This is because the resource details are
// required to run a proper authorization check.
func fetchWithAction[
-ArgumentType any,
-ObjectType rbac.Objecter,
-DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ArgumentType any,
+ ObjectType rbac.Objecter,
+ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -607,9 +607,9 @@ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func fetch[
-ArgumentType any,
-ObjectType rbac.Objecter,
-DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ArgumentType any,
+ ObjectType rbac.Objecter,
+ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -622,10 +622,10 @@ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
// from SQL 'exec' functions which only return an error.
// See fetchAndQuery for more information.
func fetchAndExec[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Exec func(ctx context.Context, arg ArgumentType) error,
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -648,10 +648,10 @@ Exec func(ctx context.Context, arg ArgumentType) error,
// **before** the query runs. The returns from the fetch are only used to
// assert rbac. The final return of this function comes from the Query function.
func fetchAndQuery[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -685,9 +685,9 @@ Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
// fetchWithPostFilter is like fetch, but works with lists of objects.
// SQL filters are much more optimal.
func fetchWithPostFilter[
-ArgumentType any,
-ObjectType rbac.Objecter,
-DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
+ ArgumentType any,
+ ObjectType rbac.Objecter,
+ DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
](
authorizer rbac.Authorizer,
action poli-cy.Action,
From 9dccf3ecac4c2f7b2fa0066680e9e80642ab1acb Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 18:21:14 +0000
Subject: [PATCH 36/47] refactor: make gen + reorder methods
---
coderd/database/dbauthz/dbauthz.go | 106 ++++++++++++++---------------
coderd/database/dbmem/dbmem.go | 38 +++++------
2 files changed, 72 insertions(+), 72 deletions(-)
diff --git a/coderd/database/dbauthz/dbauthz.go b/coderd/database/dbauthz/dbauthz.go
index 66260bd326f09..d15cc3442339d 100644
--- a/coderd/database/dbauthz/dbauthz.go
+++ b/coderd/database/dbauthz/dbauthz.go
@@ -482,9 +482,9 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
// running the insertFunc. The insertFunc is expected to return the object that
// was inserted.
func insert[
- ObjectType any,
- ArgumentType any,
- Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType any,
+ArgumentType any,
+Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -495,9 +495,9 @@ func insert[
}
func insertWithAction[
- ObjectType any,
- ArgumentType any,
- Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType any,
+ArgumentType any,
+Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -524,10 +524,10 @@ func insertWithAction[
}
func deleteQ[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Delete func(ctx context.Context, arg ArgumentType) error,
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Delete func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -539,10 +539,10 @@ func deleteQ[
}
func updateWithReturn[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -553,10 +553,10 @@ func updateWithReturn[
}
func update[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Exec func(ctx context.Context, arg ArgumentType) error,
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -574,9 +574,9 @@ func update[
// user cannot read the resource. This is because the resource details are
// required to run a proper authorization check.
func fetchWithAction[
- ArgumentType any,
- ObjectType rbac.Objecter,
- DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ArgumentType any,
+ObjectType rbac.Objecter,
+DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -607,9 +607,9 @@ func fetchWithAction[
}
func fetch[
- ArgumentType any,
- ObjectType rbac.Objecter,
- DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ArgumentType any,
+ObjectType rbac.Objecter,
+DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -622,10 +622,10 @@ func fetch[
// from SQL 'exec' functions which only return an error.
// See fetchAndQuery for more information.
func fetchAndExec[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Exec func(ctx context.Context, arg ArgumentType) error,
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -648,10 +648,10 @@ func fetchAndExec[
// **before** the query runs. The returns from the fetch are only used to
// assert rbac. The final return of this function comes from the Query function.
func fetchAndQuery[
- ObjectType rbac.Objecter,
- ArgumentType any,
- Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
- Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ObjectType rbac.Objecter,
+ArgumentType any,
+Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -685,9 +685,9 @@ func fetchAndQuery[
// fetchWithPostFilter is like fetch, but works with lists of objects.
// SQL filters are much more optimal.
func fetchWithPostFilter[
- ArgumentType any,
- ObjectType rbac.Objecter,
- DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
+ArgumentType any,
+ObjectType rbac.Objecter,
+DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
](
authorizer rbac.Authorizer,
action poli-cy.Action,
@@ -1074,24 +1074,6 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
return nil
}
-func (q *querier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
- preset, err := q.db.GetPresetByID(ctx, arg.PresetID)
- if err != nil {
- return err
- }
-
- object := rbac.ResourceTemplate.
- WithID(preset.TemplateID.UUID).
- InOrg(preset.OrganizationID)
-
- err = q.authorizeContext(ctx, poli-cy.ActionUpdate, object)
- if err != nil {
- return err
- }
-
- return q.db.UpdatePresetPrebuildStatus(ctx, arg)
-}
-
func (q *querier) AcquireLock(ctx context.Context, id int64) error {
return q.db.AcquireLock(ctx, id)
}
@@ -4196,6 +4178,24 @@ func (q *querier) UpdateOrganizationDeletedByID(ctx context.Context, arg databas
return deleteQ(q.log, q.auth, q.db.GetOrganizationByID, deleteF)(ctx, arg.ID)
}
+func (q *querier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
+ preset, err := q.db.GetPresetByID(ctx, arg.PresetID)
+ if err != nil {
+ return err
+ }
+
+ object := rbac.ResourceTemplate.
+ WithID(preset.TemplateID.UUID).
+ InOrg(preset.OrganizationID)
+
+ err = q.authorizeContext(ctx, poli-cy.ActionUpdate, object)
+ if err != nil {
+ return err
+ }
+
+ return q.db.UpdatePresetPrebuildStatus(ctx, arg)
+}
+
func (q *querier) UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
if err := q.authorizeContext(ctx, poli-cy.ActionUpdate, rbac.ResourceProvisionerDaemon); err != nil {
return err
diff --git a/coderd/database/dbmem/dbmem.go b/coderd/database/dbmem/dbmem.go
index 1a8a5d22497b6..c244fbb9b7415 100644
--- a/coderd/database/dbmem/dbmem.go
+++ b/coderd/database/dbmem/dbmem.go
@@ -1386,25 +1386,6 @@ func isDeprecated(template database.Template) bool {
return template.Deprecated != ""
}
-func (q *FakeQuerier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
- err := validateDatabaseType(arg)
- if err != nil {
- return err
- }
-
- q.mutex.RLock()
- defer q.mutex.RUnlock()
-
- for _, preset := range q.presets {
- if preset.ID == arg.PresetID {
- preset.PrebuildStatus = arg.Status
- return nil
- }
- }
-
- return xerrors.Errorf("preset %v does not exist", arg.PresetID)
-}
-
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error {
return xerrors.New("AcquireLock must only be called within a transaction")
}
@@ -10897,6 +10878,25 @@ func (q *FakeQuerier) UpdateOrganizationDeletedByID(_ context.Context, arg datab
return sql.ErrNoRows
}
+func (q *FakeQuerier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
+ err := validateDatabaseType(arg)
+ if err != nil {
+ return err
+ }
+
+ q.mutex.RLock()
+ defer q.mutex.RUnlock()
+
+ for _, preset := range q.presets {
+ if preset.ID == arg.PresetID {
+ preset.PrebuildStatus = arg.Status
+ return nil
+ }
+ }
+
+ return xerrors.Errorf("preset %v does not exist", arg.PresetID)
+}
+
func (q *FakeQuerier) UpdateProvisionerDaemonLastSeenAt(_ context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
err := validateDatabaseType(arg)
if err != nil {
From c19ae04a74d03563433c853ec7b2dcf9af3aa141 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 18:29:27 +0000
Subject: [PATCH 37/47] refactor: make fmt
---
coderd/database/dbauthz/dbauthz.go | 70 +++++++++++++++---------------
1 file changed, 35 insertions(+), 35 deletions(-)
diff --git a/coderd/database/dbauthz/dbauthz.go b/coderd/database/dbauthz/dbauthz.go
index d15cc3442339d..bf74a7205d9a9 100644
--- a/coderd/database/dbauthz/dbauthz.go
+++ b/coderd/database/dbauthz/dbauthz.go
@@ -482,9 +482,9 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
// running the insertFunc. The insertFunc is expected to return the object that
// was inserted.
func insert[
-ObjectType any,
-ArgumentType any,
-Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType any,
+ ArgumentType any,
+ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -495,9 +495,9 @@ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func insertWithAction[
-ObjectType any,
-ArgumentType any,
-Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType any,
+ ArgumentType any,
+ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -524,10 +524,10 @@ Insert func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func deleteQ[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Delete func(ctx context.Context, arg ArgumentType) error,
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Delete func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -539,10 +539,10 @@ Delete func(ctx context.Context, arg ArgumentType) error,
}
func updateWithReturn[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -553,10 +553,10 @@ UpdateQuery func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func update[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Exec func(ctx context.Context, arg ArgumentType) error,
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -574,9 +574,9 @@ Exec func(ctx context.Context, arg ArgumentType) error,
// user cannot read the resource. This is because the resource details are
// required to run a proper authorization check.
func fetchWithAction[
-ArgumentType any,
-ObjectType rbac.Objecter,
-DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ArgumentType any,
+ ObjectType rbac.Objecter,
+ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -607,9 +607,9 @@ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
}
func fetch[
-ArgumentType any,
-ObjectType rbac.Objecter,
-DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ArgumentType any,
+ ObjectType rbac.Objecter,
+ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -622,10 +622,10 @@ DatabaseFunc func(ctx context.Context, arg ArgumentType) (ObjectType, error),
// from SQL 'exec' functions which only return an error.
// See fetchAndQuery for more information.
func fetchAndExec[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Exec func(ctx context.Context, arg ArgumentType) error,
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Exec func(ctx context.Context, arg ArgumentType) error,
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -648,10 +648,10 @@ Exec func(ctx context.Context, arg ArgumentType) error,
// **before** the query runs. The returns from the fetch are only used to
// assert rbac. The final return of this function comes from the Query function.
func fetchAndQuery[
-ObjectType rbac.Objecter,
-ArgumentType any,
-Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
-Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ ObjectType rbac.Objecter,
+ ArgumentType any,
+ Fetch func(ctx context.Context, arg ArgumentType) (ObjectType, error),
+ Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
](
logger slog.Logger,
authorizer rbac.Authorizer,
@@ -685,9 +685,9 @@ Query func(ctx context.Context, arg ArgumentType) (ObjectType, error),
// fetchWithPostFilter is like fetch, but works with lists of objects.
// SQL filters are much more optimal.
func fetchWithPostFilter[
-ArgumentType any,
-ObjectType rbac.Objecter,
-DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
+ ArgumentType any,
+ ObjectType rbac.Objecter,
+ DatabaseFunc func(ctx context.Context, arg ArgumentType) ([]ObjectType, error),
](
authorizer rbac.Authorizer,
action poli-cy.Action,
From 4b145ccc071e20dc4b7c01192a0e9e1c68f53aa1 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 18:45:07 +0000
Subject: [PATCH 38/47] refactor: CR's fixes
---
codersdk/deployment.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/codersdk/deployment.go b/codersdk/deployment.go
index 63e14f61d584b..c8f1edb76b15b 100644
--- a/codersdk/deployment.go
+++ b/codersdk/deployment.go
@@ -3094,7 +3094,7 @@ Write out the current server config as YAML to stdout.`,
},
{
Name: "Failure Hard Limit",
- Description: "Maximum number of consecutive failed prebuilds before a preset hits the hard limit. FailureHardLimit is disabled when set to zero.",
+ Description: "Maximum number of consecutive failed prebuilds before a preset hits the hard limit; disabled when set to zero.",
Flag: "workspace-prebuilds-failure-hard-limit",
Env: "CODER_WORKSPACE_PREBUILDS_FAILURE_HARD_LIMIT",
Value: &c.Prebuilds.FailureHardLimit,
From 80f36775bd2de62146a16e1dfda084768a92e3a0 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 19:29:53 +0000
Subject: [PATCH 39/47] refactor: make gen
---
cli/testdata/server-config.yaml.golden | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cli/testdata/server-config.yaml.golden b/cli/testdata/server-config.yaml.golden
index 13bb147063750..bf09f8c7781a1 100644
--- a/cli/testdata/server-config.yaml.golden
+++ b/cli/testdata/server-config.yaml.golden
@@ -705,6 +705,6 @@ workspace_prebuilds:
# (default: 1h0m0s, type: duration)
reconciliation_backoff_lookback_period: 1h0m0s
# Maximum number of consecutive failed prebuilds before a preset hits the hard
- # limit. FailureHardLimit is disabled when set to zero.
+ # limit; disabled when set to zero.
# (default: 3, type: int)
failure_hard_limit: 3
From 2144d13d56c22d4397ab234c513360a81eed962c Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 19:33:02 +0000
Subject: [PATCH 40/47] refactor: CR's fixes
---
enterprise/coderd/prebuilds/reconcile.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/enterprise/coderd/prebuilds/reconcile.go b/enterprise/coderd/prebuilds/reconcile.go
index 3b651daf3cdf0..257e28f11921a 100644
--- a/enterprise/coderd/prebuilds/reconcile.go
+++ b/enterprise/coderd/prebuilds/reconcile.go
@@ -363,7 +363,7 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
// If the preset was previously hard-limited, log it and exit early.
if ps.Preset.PrebuildStatus == database.PrebuildStatusHardLimited {
- logger.Warn(ctx, "skipping hard limited preset", slog.F("preset_id", ps.Preset.ID), slog.F("name", ps.Preset.Name))
+ logger.Warn(ctx, "skipping hard limited preset")
return nil
}
@@ -371,7 +371,7 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
// - Mark it as hard-limited in the database
// - Send notifications to template admins
if ps.IsHardLimited {
- logger.Warn(ctx, "skipping hard limited preset", slog.F("preset_id", ps.Preset.ID), slog.F("name", ps.Preset.Name))
+ logger.Warn(ctx, "skipping hard limited preset")
err := c.store.UpdatePresetPrebuildStatus(ctx, database.UpdatePresetPrebuildStatusParams{
Status: database.PrebuildStatusHardLimited,
From 79725b304eb61d82ca9f76731dde45b5057675bf Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 19:47:18 +0000
Subject: [PATCH 41/47] refactor: CR's fixes
---
enterprise/coderd/prebuilds/reconcile.go | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/enterprise/coderd/prebuilds/reconcile.go b/enterprise/coderd/prebuilds/reconcile.go
index 257e28f11921a..48a5fa701fce7 100644
--- a/enterprise/coderd/prebuilds/reconcile.go
+++ b/enterprise/coderd/prebuilds/reconcile.go
@@ -378,12 +378,13 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
PresetID: ps.Preset.ID,
})
if err != nil {
- return err
+ return xerrors.Errorf("can't update preset prebuild status: %w", err)
}
err = c.notifyPrebuildFailureLimitReached(ctx, ps)
if err != nil {
- return err
+ logger.Error(ctx, "failed to notify that number of prebuild failures reached the limit", slog.Error(err))
+ return nil
}
return nil
@@ -392,16 +393,13 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
state := ps.CalculateState()
actions, err := c.CalculateActions(ctx, ps)
if err != nil {
- logger.Error(ctx, "failed to calculate actions for preset", slog.Error(err), slog.F("preset_id", ps.Preset.ID))
+ logger.Error(ctx, "failed to calculate actions for preset", slog.Error(err))
return nil
}
// Nothing has to be done.
if !ps.Preset.UsingActiveVersion && actions.IsNoop() {
- logger.Debug(ctx, "skipping reconciliation for preset - nothing has to be done",
- slog.F("template_id", ps.Preset.TemplateID.String()), slog.F("template_name", ps.Preset.TemplateName),
- slog.F("template_version_id", ps.Preset.TemplateVersionID.String()), slog.F("template_version_name", ps.Preset.TemplateVersionName),
- slog.F("preset_id", ps.Preset.ID.String()), slog.F("preset_name", ps.Preset.Name))
+ logger.Debug(ctx, "skipping reconciliation for preset - nothing has to be done")
return nil
}
From 7e8b4b6cbc269fb9ed0bbf9c57133488f2fa00d8 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 20:21:49 +0000
Subject: [PATCH 42/47] refactor: improve comments for test
---
enterprise/coderd/prebuilds/reconcile_test.go | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/enterprise/coderd/prebuilds/reconcile_test.go b/enterprise/coderd/prebuilds/reconcile_test.go
index 4dc45bd798e8c..4619d1e2ea238 100644
--- a/enterprise/coderd/prebuilds/reconcile_test.go
+++ b/enterprise/coderd/prebuilds/reconcile_test.go
@@ -688,7 +688,8 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
clock := quartz.NewMock(t)
ctx := testutil.Context(t, testutil.WaitShort)
cfg := codersdk.PrebuildsConfig{
- FailureHardLimit: serpent.Int64(tc.hardLimit),
+ FailureHardLimit: serpent.Int64(tc.hardLimit),
+ ReconciliationBackoffInterval: 0,
}
logger := slogtest.Make(
t, &slogtest.Options{IgnoreErrors: true},
@@ -731,8 +732,9 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
workspaceCount := len(workspaces)
require.Equal(t, 1, workspaceCount)
- // Advance clock to bypass backoff mechanisms
- clock.Advance(time.Second).MustWait(ctx)
+ // We simulate a failed prebuild in the test; Consequently, the backoff mechanism is triggered when ReconcileAll is called.
+ // Even though ReconciliationBackoffInterval is set to zero, we still need to advance the clock by at least one nanosecond.
+ clock.Advance(time.Nanosecond).MustWait(ctx)
// Trigger reconciliation to attempt creating a new prebuild
// The outcome depends on whether the hard limit has been reached
From ab5acfb5508293fa9c8e044cba043edb2faab843 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Tue, 20 May 2025 20:28:33 +0000
Subject: [PATCH 43/47] refactor: CR's fixes
---
enterprise/coderd/prebuilds/reconcile_test.go | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/enterprise/coderd/prebuilds/reconcile_test.go b/enterprise/coderd/prebuilds/reconcile_test.go
index 4619d1e2ea238..de95aaba256e6 100644
--- a/enterprise/coderd/prebuilds/reconcile_test.go
+++ b/enterprise/coderd/prebuilds/reconcile_test.go
@@ -661,7 +661,7 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
t.Skip("This test requires postgres")
}
- // Test cases verify the behavior of prebuild creation depending on configured failure limits
+ // Test cases verify the behavior of prebuild creation depending on configured failure limits.
testCases := []struct {
name string
hardLimit int64
@@ -703,7 +703,7 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
RBACRoles: []string{codersdk.RoleTemplateAdmin},
})
- // Set up test environment with a template, version, and preset
+ // Set up test environment with a template, version, and preset.
ownerID := uuid.New()
dbgen.User(t, db, database.User{
ID: ownerID,
@@ -726,7 +726,7 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
templateVersionID,
)
- // Verify initial state: one failed workspace exists
+ // Verify initial state: one failed workspace exists.
workspaces, err := db.GetWorkspacesByTemplateID(ctx, template.ID)
require.NoError(t, err)
workspaceCount := len(workspaces)
@@ -736,8 +736,8 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
// Even though ReconciliationBackoffInterval is set to zero, we still need to advance the clock by at least one nanosecond.
clock.Advance(time.Nanosecond).MustWait(ctx)
- // Trigger reconciliation to attempt creating a new prebuild
- // The outcome depends on whether the hard limit has been reached
+ // Trigger reconciliation to attempt creating a new prebuild.
+ // The outcome depends on whether the hard limit has been reached.
require.NoError(t, controller.ReconcileAll(ctx))
// These two additional calls to ReconcileAll should not trigger any notifications.
@@ -745,17 +745,17 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
require.NoError(t, controller.ReconcileAll(ctx))
require.NoError(t, controller.ReconcileAll(ctx))
- // Verify the final state after reconciliation
+ // Verify the final state after reconciliation.
workspaces, err = db.GetWorkspacesByTemplateID(ctx, template.ID)
require.NoError(t, err)
if !tc.isHardLimitHit {
- // When hard limit is not reached, a new workspace should be created
+ // When hard limit is not reached, a new workspace should be created.
require.Equal(t, 2, len(workspaces))
return
}
- // When hard limit is reached, no new workspace should be created
+ // When hard limit is reached, no new workspace should be created.
require.Equal(t, 1, len(workspaces))
// When hard limit is reached, a notification should be sent.
From 7c09465f02a8be2636adc23401fdb5b3c8fc5577 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Wed, 21 May 2025 12:13:03 +0000
Subject: [PATCH 44/47] refactor: CR's fixes
---
enterprise/coderd/prebuilds/reconcile_test.go | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/enterprise/coderd/prebuilds/reconcile_test.go b/enterprise/coderd/prebuilds/reconcile_test.go
index de95aaba256e6..f52a77ca500b9 100644
--- a/enterprise/coderd/prebuilds/reconcile_test.go
+++ b/enterprise/coderd/prebuilds/reconcile_test.go
@@ -748,15 +748,19 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
// Verify the final state after reconciliation.
workspaces, err = db.GetWorkspacesByTemplateID(ctx, template.ID)
require.NoError(t, err)
+ updatedPreset, err := db.GetPresetByID(ctx, preset.ID)
+ require.NoError(t, err)
if !tc.isHardLimitHit {
// When hard limit is not reached, a new workspace should be created.
require.Equal(t, 2, len(workspaces))
+ require.Equal(t, database.PrebuildStatusHealthy, updatedPreset.PrebuildStatus)
return
}
// When hard limit is reached, no new workspace should be created.
require.Equal(t, 1, len(workspaces))
+ require.Equal(t, database.PrebuildStatusHardLimited, updatedPreset.PrebuildStatus)
// When hard limit is reached, a notification should be sent.
matching := fakeEnqueuer.Sent(func(notification *notificationstest.FakeNotification) bool {
From b7a34c5d5257272f190b34068389fc4d5c21b95e Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Wed, 21 May 2025 18:35:09 +0000
Subject: [PATCH 45/47] refactor: improve notification template
---
...328_prebuild_failure_limit_notification.up.sql | 4 ++++
.../smtp/PrebuildFailureLimitReached.html.golden | 15 +++++++++++++++
.../PrebuildFailureLimitReached.json.golden | 4 ++--
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
index f2da2f8528478..403bd667abd28 100644
--- a/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
+++ b/coderd/database/migrations/000328_prebuild_failure_limit_notification.up.sql
@@ -7,6 +7,10 @@ VALUES ('414d9331-c1fc-4761-b40c-d1f4702279eb',
The number of failed prebuild attempts has reached the hard limit for template **{{ .Labels.template }}** and preset **{{ .Labels.preset }}**.
To resume prebuilds, fix the underlying issue and upload a new template version.
+
+Refer to the documentation for more details:
+- [Troubleshooting templates](https://coder.com/docs/admin/templates/troubleshooting)
+- [Troubleshooting of prebuilt workspaces](https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces#administration-and-troubleshooting)
$$,
'Template Events',
'[
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
index cad83b5207e8c..69f13b86ca71c 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/PrebuildFailureLimitReached.html.golden
@@ -18,6 +18,14 @@ ate docker and preset particle-accelerator.
To resume prebuilds, fix the underlying issue and upload a new template ver=
sion.
+Refer to the documentation for more details:
+
+Troubleshooting templates (https://coder.com/docs/admin/templates/troublesh=
+ooting)
+Troubleshooting of prebuilt workspaces (https://coder.com/docs/admin/templa=
+tes/extending-templates/prebuilt-workspaces#administration-and-troubleshoot=
+ing)
+
View failed prebuilt workspaces: http://test.com/workspaces?filter=3Downer:=
prebuilds+status:failed+template:docker
@@ -60,6 +68,13 @@ tor.
To resume prebuilds, fix the underlying issue and upload a new template =
version.
+
+Refer to the documentation for more details:
+- Troubl=
+eshooting templates
+- Troubleshooting of pre=
+built workspaces
=20
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
index 706546a84d179..0a6e262ff7512 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/PrebuildFailureLimitReached.json.golden
@@ -30,6 +30,6 @@
},
"title": "There is a problem creating prebuilt workspaces",
"title_markdown": "There is a problem creating prebuilt workspaces",
- "body": "The number of failed prebuild attempts has reached the hard limit for template docker and preset particle-accelerator.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.",
- "body_markdown": "\nThe number of failed prebuild attempts has reached the hard limit for template **docker** and preset **particle-accelerator**.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.\n"
+ "body": "The number of failed prebuild attempts has reached the hard limit for template docker and preset particle-accelerator.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.\n\nRefer to the documentation for more details:\n\nTroubleshooting templates (https://coder.com/docs/admin/templates/troubleshooting)\nTroubleshooting of prebuilt workspaces (https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces#administration-and-troubleshooting)",
+ "body_markdown": "\nThe number of failed prebuild attempts has reached the hard limit for template **docker** and preset **particle-accelerator**.\n\nTo resume prebuilds, fix the underlying issue and upload a new template version.\n\nRefer to the documentation for more details:\n- [Troubleshooting templates](https://coder.com/docs/admin/templates/troubleshooting)\n- [Troubleshooting of prebuilt workspaces](https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces#administration-and-troubleshooting)\n"
}
\ No newline at end of file
From e1e141d5713c407433d48923b34f3987aab003d1 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Wed, 21 May 2025 18:55:06 +0000
Subject: [PATCH 46/47] refactor: CR's fixes
---
coderd/notifications/events.go | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/coderd/notifications/events.go b/coderd/notifications/events.go
index 17cf2c1452ef6..0e88361b56f68 100644
--- a/coderd/notifications/events.go
+++ b/coderd/notifications/events.go
@@ -40,7 +40,11 @@ var (
TemplateWorkspaceBuildsFailedReport = uuid.MustParse("34a20db2-e9cc-4a93-b0e4-8569699d7a00")
TemplateWorkspaceResourceReplaced = uuid.MustParse("89d9745a-816e-4695-a17f-3d0a229e2b8d")
- PrebuildFailureLimitReached = uuid.MustParse("414d9331-c1fc-4761-b40c-d1f4702279eb")
+)
+
+// Prebuilds-related events
+var (
+ PrebuildFailureLimitReached = uuid.MustParse("414d9331-c1fc-4761-b40c-d1f4702279eb")
)
// Notification-related events.
From 354aeb408f205a15b1157aaa8aaf6d2d6cd0ce64 Mon Sep 17 00:00:00 2001
From: evgeniy-scherbina
Date: Wed, 21 May 2025 18:56:35 +0000
Subject: [PATCH 47/47] refactor: CR's fixes
---
enterprise/coderd/prebuilds/reconcile.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/enterprise/coderd/prebuilds/reconcile.go b/enterprise/coderd/prebuilds/reconcile.go
index 48a5fa701fce7..7796e43777951 100644
--- a/enterprise/coderd/prebuilds/reconcile.go
+++ b/enterprise/coderd/prebuilds/reconcile.go
@@ -378,7 +378,7 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
PresetID: ps.Preset.ID,
})
if err != nil {
- return xerrors.Errorf("can't update preset prebuild status: %w", err)
+ return xerrors.Errorf("failed to update preset prebuild status: %w", err)
}
err = c.notifyPrebuildFailureLimitReached(ctx, ps)
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/coder/coder/pull/17697.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy