- Notifications
You must be signed in to change notification settings - Fork907
feat: cancel stuck pending jobs#17803
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
+773 −291
Merged
Changes fromall commits
Commits
Show all changes
24 commits Select commitHold shift + click to select a range
0f51f35
added queries for fetching NotStartedProvisionerJobs
ibetitsmike2f3d606
added detector handling of not started jobs
ibetitsmike4b252eb
filling out started_at when unhanging not started jobs
ibetitsmikeca49519
WIP
ibetitsmikeaf994c2
refactored to reaper & added tests
ibetitsmike3815727
Revert "filling out started_at when unhanging not started jobs"
ibetitsmikeb65f620
created new ORM update to avoid forcing setting StartedAt on every Co…
ibetitsmike3c7c323
added missing dbauthz tests
ibetitsmike35df01f
added checks for StartedAt value in the updated jobs
ibetitsmike8aa1ee2
refactor from reaper to jobreaper
ibetitsmike4385933
WIP
ibetitsmike96fee51
WIP
ibetitsmiked8db119
WIP
ibetitsmike5120fb1
WIP
ibetitsmike8d4fa5a
fixed sql comments
ibetitsmike18b809c
taking a step back with RBAC
ibetitsmike0fe1404
WIP
ibetitsmike77be34e
WIP
ibetitsmike4351529
WIP
ibetitsmikec03bfa3
fixed InOrg check for provisionerjob resource
ibetitsmikea15bd1c
PR review; naming in the comments, added comments for SQL, less verbo…
ibetitsmike5b9348f
fixes to tests after lint remove rand
ibetitsmike91d2d32
readded rand to fix gen failing in CI
ibetitsmike767cb77
adjusted TODOs
ibetitsmikeFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
12 changes: 6 additions & 6 deletionscli/server.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioncli/testdata/server-config.yaml.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletionscoderd/coderdtest/coderdtest.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
139 changes: 80 additions & 59 deletionscoderd/database/dbauthz/dbauthz.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -170,10 +170,10 @@ var ( | ||
Identifier: rbac.RoleIdentifier{Name: "provisionerd"}, | ||
DisplayName: "Provisioner Daemon", | ||
Site: rbac.Permissions(map[string][]policy.Action{ | ||
rbac.ResourceProvisionerJobs.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionCreate}, | ||
rbac.ResourceFile.Type:{policy.ActionRead}, | ||
rbac.ResourceSystem.Type:{policy.WildcardSymbol}, | ||
rbac.ResourceTemplate.Type:{policy.ActionRead, policy.ActionUpdate}, | ||
// Unsure why provisionerd needs update and read personal | ||
rbac.ResourceUser.Type: {policy.ActionRead, policy.ActionReadPersonal, policy.ActionUpdatePersonal}, | ||
rbac.ResourceWorkspaceDormant.Type: {policy.ActionDelete, policy.ActionRead, policy.ActionUpdate, policy.ActionWorkspaceStop}, | ||
@@ -219,19 +219,20 @@ var ( | ||
Scope: rbac.ScopeAll, | ||
}.WithCachedASTValue() | ||
// Seereaper package. | ||
subjectJobReaper = rbac.Subject{ | ||
Type: rbac.SubjectTypeJobReaper, | ||
FriendlyName: "Job Reaper", | ||
ID: uuid.Nil.String(), | ||
Roles: rbac.Roles([]rbac.Role{ | ||
{ | ||
Identifier: rbac.RoleIdentifier{Name: "jobreaper"}, | ||
DisplayName: "Job Reaper Daemon", | ||
Site: rbac.Permissions(map[string][]policy.Action{ | ||
rbac.ResourceSystem.Type: {policy.WildcardSymbol}, | ||
ibetitsmike marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
rbac.ResourceTemplate.Type: {policy.ActionRead}, | ||
rbac.ResourceWorkspace.Type: {policy.ActionRead, policy.ActionUpdate}, | ||
rbac.ResourceProvisionerJobs.Type: {policy.ActionRead, policy.ActionUpdate}, | ||
}), | ||
Org: map[string][]rbac.Permission{}, | ||
User: []rbac.Permission{}, | ||
@@ -346,6 +347,7 @@ var ( | ||
rbac.ResourceNotificationTemplate.Type: {policy.ActionCreate, policy.ActionUpdate, policy.ActionDelete}, | ||
rbac.ResourceCryptoKey.Type: {policy.ActionCreate, policy.ActionUpdate, policy.ActionDelete}, | ||
rbac.ResourceFile.Type: {policy.ActionCreate, policy.ActionRead}, | ||
rbac.ResourceProvisionerJobs.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionCreate}, | ||
}), | ||
Org: map[string][]rbac.Permission{}, | ||
User: []rbac.Permission{}, | ||
@@ -407,10 +409,10 @@ func AsAutostart(ctx context.Context) context.Context { | ||
return As(ctx, subjectAutostart) | ||
} | ||
//AsJobReaper returns a context with an actor that has permissions required | ||
// forreaper.Detector to function. | ||
funcAsJobReaper(ctx context.Context) context.Context { | ||
return As(ctx,subjectJobReaper) | ||
} | ||
// AsKeyRotator returns a context with an actor that has permissions required for rotating crypto keys. | ||
@@ -1085,11 +1087,10 @@ func (q *querier) AcquireNotificationMessages(ctx context.Context, arg database. | ||
return q.db.AcquireNotificationMessages(ctx, arg) | ||
} | ||
func (q *querier) AcquireProvisionerJob(ctx context.Context, arg database.AcquireProvisionerJobParams) (database.ProvisionerJob, error) { | ||
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerJobs); err != nil { | ||
return database.ProvisionerJob{}, err | ||
} | ||
return q.db.AcquireProvisionerJob(ctx, arg) | ||
} | ||
@@ -1912,14 +1913,6 @@ func (q *querier) GetHealthSettings(ctx context.Context) (string, error) { | ||
return q.db.GetHealthSettings(ctx) | ||
} | ||
func (q *querier) GetInboxNotificationByID(ctx context.Context, id uuid.UUID) (database.InboxNotification, error) { | ||
return fetchWithAction(q.log, q.auth, policy.ActionRead, q.db.GetInboxNotificationByID)(ctx, id) | ||
} | ||
@@ -2307,6 +2300,13 @@ func (q *querier) GetProvisionerJobByID(ctx context.Context, id uuid.UUID) (data | ||
return job, nil | ||
} | ||
func (q *querier) GetProvisionerJobByIDForUpdate(ctx context.Context, id uuid.UUID) (database.ProvisionerJob, error) { | ||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs); err != nil { | ||
return database.ProvisionerJob{}, err | ||
} | ||
return q.db.GetProvisionerJobByIDForUpdate(ctx, id) | ||
} | ||
func (q *querier) GetProvisionerJobTimingsByJobID(ctx context.Context, jobID uuid.UUID) ([]database.ProvisionerJobTiming, error) { | ||
_, err := q.GetProvisionerJobByID(ctx, jobID) | ||
if err != nil { | ||
@@ -2315,31 +2315,49 @@ func (q *querier) GetProvisionerJobTimingsByJobID(ctx context.Context, jobID uui | ||
return q.db.GetProvisionerJobTimingsByJobID(ctx, jobID) | ||
} | ||
func (q *querier) GetProvisionerJobsByIDs(ctx context.Context, ids []uuid.UUID) ([]database.ProvisionerJob, error) { | ||
provisionerJobs, err := q.db.GetProvisionerJobsByIDs(ctx, ids) | ||
if err != nil { | ||
return nil, err | ||
} | ||
orgIDs := make(map[uuid.UUID]struct{}) | ||
for _, job := range provisionerJobs { | ||
orgIDs[job.OrganizationID] = struct{}{} | ||
} | ||
for orgID := range orgIDs { | ||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs.InOrg(orgID)); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return provisionerJobs, nil | ||
} | ||
func (q *querier) GetProvisionerJobsByIDsWithQueuePosition(ctx context.Context, ids []uuid.UUID) ([]database.GetProvisionerJobsByIDsWithQueuePositionRow, error) { | ||
// TODO: Remove this once we have a proper rbac check for provisioner jobs. | ||
// Details in https://github.com/coder/coder/issues/16160 | ||
return q.db.GetProvisionerJobsByIDsWithQueuePosition(ctx, ids) | ||
} | ||
func (q *querier) GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner(ctx context.Context, arg database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerParams) ([]database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow, error) { | ||
// TODO: Remove this once we have a proper rbac check for provisioner jobs. | ||
// Details in https://github.com/coder/coder/issues/16160 | ||
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner)(ctx, arg) | ||
} | ||
func (q *querier) GetProvisionerJobsCreatedAfter(ctx context.Context, createdAt time.Time) ([]database.ProvisionerJob, error) { | ||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs); err != nil { | ||
return nil, err | ||
} | ||
return q.db.GetProvisionerJobsCreatedAfter(ctx, createdAt) | ||
} | ||
func (q *querier) GetProvisionerJobsToBeReaped(ctx context.Context, arg database.GetProvisionerJobsToBeReapedParams) ([]database.ProvisionerJob, error) { | ||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs); err != nil { | ||
return nil, err | ||
} | ||
return q.db.GetProvisionerJobsToBeReaped(ctx, arg) | ||
} | ||
func (q *querier) GetProvisionerKeyByHashedSecret(ctx context.Context, hashedSecret []byte) (database.ProvisionerKey, error) { | ||
return fetch(q.log, q.auth, q.db.GetProvisionerKeyByHashedSecret)(ctx, hashedSecret) | ||
} | ||
@@ -3524,27 +3542,22 @@ func (q *querier) InsertPresetParameters(ctx context.Context, arg database.Inser | ||
return q.db.InsertPresetParameters(ctx, arg) | ||
} | ||
func (q *querier) InsertProvisionerJob(ctx context.Context, arg database.InsertProvisionerJobParams) (database.ProvisionerJob, error) { | ||
// TODO: Remove this once we have a proper rbac check for provisioner jobs. | ||
// Details in https://github.com/coder/coder/issues/16160 | ||
return q.db.InsertProvisionerJob(ctx, arg) | ||
} | ||
func (q *querier) InsertProvisionerJobLogs(ctx context.Context, arg database.InsertProvisionerJobLogsParams) ([]database.ProvisionerJobLog, error) { | ||
// TODO: Remove this once we have a proper rbac check for provisioner jobs. | ||
// Details in https://github.com/coder/coder/issues/16160 | ||
return q.db.InsertProvisionerJobLogs(ctx, arg) | ||
} | ||
func (q *querier) InsertProvisionerJobTimings(ctx context.Context, arg database.InsertProvisionerJobTimingsParams) ([]database.ProvisionerJobTiming, error) { | ||
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerJobs); err != nil { | ||
return nil, err | ||
} | ||
return q.db.InsertProvisionerJobTimings(ctx, arg) | ||
} | ||
@@ -4167,15 +4180,17 @@ func (q *querier) UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg dat | ||
return q.db.UpdateProvisionerDaemonLastSeenAt(ctx, arg) | ||
} | ||
func (q *querier) UpdateProvisionerJobByID(ctx context.Context, arg database.UpdateProvisionerJobByIDParams) error { | ||
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerJobs); err != nil { | ||
return err | ||
} | ||
return q.db.UpdateProvisionerJobByID(ctx, arg) | ||
} | ||
func (q *querier) UpdateProvisionerJobWithCancelByID(ctx context.Context, arg database.UpdateProvisionerJobWithCancelByIDParams) error { | ||
// TODO: Remove this once we have a proper rbac check for provisioner jobs. | ||
// Details in https://github.com/coder/coder/issues/16160 | ||
job, err := q.db.GetProvisionerJobByID(ctx, arg.ID) | ||
if err != nil { | ||
return err | ||
@@ -4242,14 +4257,20 @@ func (q *querier) UpdateProvisionerJobWithCancelByID(ctx context.Context, arg da | ||
return q.db.UpdateProvisionerJobWithCancelByID(ctx, arg) | ||
} | ||
func (q *querier) UpdateProvisionerJobWithCompleteByID(ctx context.Context, arg database.UpdateProvisionerJobWithCompleteByIDParams) error { | ||
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerJobs); err != nil { | ||
return err | ||
} | ||
return q.db.UpdateProvisionerJobWithCompleteByID(ctx, arg) | ||
} | ||
func (q *querier) UpdateProvisionerJobWithCompleteWithStartedAtByID(ctx context.Context, arg database.UpdateProvisionerJobWithCompleteWithStartedAtByIDParams) error { | ||
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerJobs); err != nil { | ||
return err | ||
} | ||
return q.db.UpdateProvisionerJobWithCompleteWithStartedAtByID(ctx, arg) | ||
} | ||
func (q *querier) UpdateReplica(ctx context.Context, arg database.UpdateReplicaParams) (database.Replica, error) { | ||
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceSystem); err != nil { | ||
return database.Replica{}, err | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.