Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(coderd): add filters and fix template for provisioner daemons#16558

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 1 commit intomainfrommafredri/feat-coderd-provisioner-id-filter
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@
"previous_job": {
"id": "======[workspace build job ID]======",
"status": "succeeded",
"template_name": "",
"template_name": "test-template",
"template_icon": "",
"template_display_name": ""
},
Expand Down
37 changes: 37 additions & 0 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

37 changes: 37 additions & 0 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

76 changes: 68 additions & 8 deletionscoderd/database/dbmem/dbmem.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3931,7 +3931,7 @@ func (q *FakeQuerier) GetProvisionerDaemonsByOrganization(_ context.Context, arg
return daemons, nil
}

func (q *FakeQuerier) GetProvisionerDaemonsWithStatusByOrganization(_ context.Context, arg database.GetProvisionerDaemonsWithStatusByOrganizationParams) ([]database.GetProvisionerDaemonsWithStatusByOrganizationRow, error) {
func (q *FakeQuerier) GetProvisionerDaemonsWithStatusByOrganization(ctx context.Context, arg database.GetProvisionerDaemonsWithStatusByOrganizationParams) ([]database.GetProvisionerDaemonsWithStatusByOrganizationRow, error) {
err := validateDatabaseType(arg)
if err != nil {
return nil, err
Expand DownExpand Up@@ -3981,6 +3981,31 @@ func (q *FakeQuerier) GetProvisionerDaemonsWithStatusByOrganization(_ context.Co
status = database.ProvisionerDaemonStatusIdle
}
}
var currentTemplate database.Template
if currentJob.ID != uuid.Nil {
var input codersdk.ProvisionerJobInput
err := json.Unmarshal(currentJob.Input, &input)
if err != nil {
return nil, err
}
if input.WorkspaceBuildID != nil {
b, err := q.getWorkspaceBuildByIDNoLock(ctx, *input.WorkspaceBuildID)
if err != nil {
return nil, err
}
input.TemplateVersionID = &b.TemplateVersionID
}
if input.TemplateVersionID != nil {
v, err := q.getTemplateVersionByIDNoLock(ctx, *input.TemplateVersionID)
if err != nil {
return nil, err
}
currentTemplate, err = q.getTemplateByIDNoLock(ctx, v.TemplateID.UUID)
if err != nil {
return nil, err
}
}
}

var previousJob database.ProvisionerJob
for _, job := range q.provisionerJobs {
Expand All@@ -3997,6 +4022,31 @@ func (q *FakeQuerier) GetProvisionerDaemonsWithStatusByOrganization(_ context.Co
}
}
}
var previousTemplate database.Template
if previousJob.ID != uuid.Nil {
var input codersdk.ProvisionerJobInput
err := json.Unmarshal(previousJob.Input, &input)
if err != nil {
return nil, err
}
if input.WorkspaceBuildID != nil {
b, err := q.getWorkspaceBuildByIDNoLock(ctx, *input.WorkspaceBuildID)
if err != nil {
return nil, err
}
input.TemplateVersionID = &b.TemplateVersionID
}
if input.TemplateVersionID != nil {
v, err := q.getTemplateVersionByIDNoLock(ctx, *input.TemplateVersionID)
if err != nil {
return nil, err
}
previousTemplate, err = q.getTemplateByIDNoLock(ctx, v.TemplateID.UUID)
if err != nil {
return nil, err
}
}
}

// Get the provisioner key name
var keyName string
Expand All@@ -4008,20 +4058,30 @@ func (q *FakeQuerier) GetProvisionerDaemonsWithStatusByOrganization(_ context.Co
}

rows = append(rows, database.GetProvisionerDaemonsWithStatusByOrganizationRow{
ProvisionerDaemon: daemon,
Status: status,
KeyName: keyName,
CurrentJobID: uuid.NullUUID{UUID: currentJob.ID, Valid: currentJob.ID != uuid.Nil},
CurrentJobStatus: database.NullProvisionerJobStatus{ProvisionerJobStatus: currentJob.JobStatus, Valid: currentJob.ID != uuid.Nil},
PreviousJobID: uuid.NullUUID{UUID: previousJob.ID, Valid: previousJob.ID != uuid.Nil},
PreviousJobStatus: database.NullProvisionerJobStatus{ProvisionerJobStatus: previousJob.JobStatus, Valid: previousJob.ID != uuid.Nil},
ProvisionerDaemon: daemon,
Status: status,
KeyName: keyName,
CurrentJobID: uuid.NullUUID{UUID: currentJob.ID, Valid: currentJob.ID != uuid.Nil},
CurrentJobStatus: database.NullProvisionerJobStatus{ProvisionerJobStatus: currentJob.JobStatus, Valid: currentJob.ID != uuid.Nil},
CurrentJobTemplateName: currentTemplate.Name,
CurrentJobTemplateDisplayName: currentTemplate.DisplayName,
CurrentJobTemplateIcon: currentTemplate.Icon,
PreviousJobID: uuid.NullUUID{UUID: previousJob.ID, Valid: previousJob.ID != uuid.Nil},
PreviousJobStatus: database.NullProvisionerJobStatus{ProvisionerJobStatus: previousJob.JobStatus, Valid: previousJob.ID != uuid.Nil},
PreviousJobTemplateName: previousTemplate.Name,
PreviousJobTemplateDisplayName: previousTemplate.DisplayName,
PreviousJobTemplateIcon: previousTemplate.Icon,
})
}

slices.SortFunc(rows, func(a, b database.GetProvisionerDaemonsWithStatusByOrganizationRow) int {
return a.ProvisionerDaemon.CreatedAt.Compare(b.ProvisionerDaemon.CreatedAt)
})

if arg.Limit.Valid && arg.Limit.Int32 > 0 && len(rows) > int(arg.Limit.Int32) {
rows = rows[:arg.Limit.Int32]
}

return rows, nil
}

Expand Down
2 changes: 2 additions & 0 deletionscoderd/database/querier.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

67 changes: 46 additions & 21 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

29 changes: 23 additions & 6 deletionscoderd/database/queries/provisionerdaemons.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,9 +45,12 @@ SELECT
current_job.job_status AS current_job_status,
previous_job.id AS previous_job_id,
previous_job.job_status AS previous_job_status,
COALESCE(tmpl.name, ''::text) AS current_job_template_name,
COALESCE(tmpl.display_name, ''::text) AS current_job_template_display_name,
COALESCE(tmpl.icon, ''::text) AS current_job_template_icon
COALESCE(current_template.name, ''::text) AS current_job_template_name,
COALESCE(current_template.display_name, ''::text) AS current_job_template_display_name,
COALESCE(current_template.icon, ''::text) AS current_job_template_icon,
COALESCE(previous_template.name, ''::text) AS previous_job_template_name,
COALESCE(previous_template.display_name, ''::text) AS previous_job_template_display_name,
COALESCE(previous_template.icon, ''::text) AS previous_job_template_icon
FROM
provisioner_daemons pd
JOIN
Expand All@@ -72,16 +75,30 @@ LEFT JOIN
LIMIT 1
)
)
-- Current job information.
LEFT JOIN
template_versions version ONversion.id = (current_job.input->>'template_version_id')::uuid
workspace_builds current_build ONcurrent_build.id =CASE WHEN current_job.input ? 'workspace_build_id' THEN(current_job.input->>'workspace_build_id')::uuid END
LEFT JOIN
templates tmpl ON tmpl.id = version.template_id
-- We should always have a template version, either explicitly or implicitly via workspace build.
template_versions current_version ON current_version.id = CASE WHEN current_job.input ? 'template_version_id' THEN (current_job.input->>'template_version_id')::uuid ELSE current_build.template_version_id END
LEFT JOIN
templates current_template ON current_template.id = current_version.template_id
-- Previous job information.
LEFT JOIN
workspace_builds previous_build ON previous_build.id = CASE WHEN previous_job.input ? 'workspace_build_id' THEN (previous_job.input->>'workspace_build_id')::uuid END
LEFT JOIN
-- We should always have a template version, either explicitly or implicitly via workspace build.
template_versions previous_version ON previous_version.id = CASE WHEN previous_job.input ? 'template_version_id' THEN (previous_job.input->>'template_version_id')::uuid ELSE previous_build.template_version_id END
LEFT JOIN
templates previous_template ON previous_template.id = previous_version.template_id
Comment on lines +78 to +93
Copy link
MemberAuthor

@mafredrimafredriFeb 13, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Review: I completed this because it was missing some things. But I wonder if we need to take RBAC into consideration now?

The endpoint previously returned a job ID/status only, now it also returns information regarding the template that job is associated with.

This has some implications considering regular members are allowed to view provisioner daemon resources. WDYT@johnstcn?

I'm not particularly fond of it, but we could add the same authorization to the API endpoint as for jobs:

// For now, only owners and template admins can access provisioner jobs.if!api.Authorize(r,policy.ActionRead,rbac.ResourceProvisionerJobs.InOrg(org.ID)) {httpapi.ResourceNotFound(rw)returnnil,false}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't know how sensitivetemplate ortemplate_version fields can be, but a red flag for me would be if this could cross org boundaries.

I think some further questions we need to answer before we can even update the RBAC rules are:

  • Who can view a template import job not linked to any workspace? (Suggestion: anyone who can read the linked template)
  • Who can view a workspace build job? (Suggestion: anyone who can read the linked workspace)

To be safe, I think we should promote the same level of access control as for provisioner jobsfor now. We should add a follow-up issue to take provisioner job ownership and template-level ACLs into account.

Does that sound reasonable to you?

mafredri reacted with thumbs up emoji
WHERE
pd.organization_id = @organization_id::uuid
AND (COALESCE(array_length(@ids::uuid[], 1), 0) = 0 OR pd.id = ANY(@ids::uuid[]))
AND (@tags::tagset = 'null'::tagset OR provisioner_tagset_contains(pd.tags::tagset, @tags::tagset))
ORDER BY
pd.created_at ASC;
pd.created_at ASC
LIMIT
sqlc.narg('limit')::int;

-- name: DeleteOldProvisionerDaemons :exec
-- Delete provisioner daemons that have been created at least a week ago
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp