- Notifications
You must be signed in to change notification settings - Fork1k
feat(coderd): add matched provisioner daemons information to more places#15688
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from11 commits
ba944ab
4e51f20
47036e8
16be03b
4304a06
9ef68dd
38788d5
1c95ffe
98521be
e1423f5
517a505
c4295ef
c5fb83b
3bd62fd
2f625bc
848338e
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cliutil | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"strings" | ||
"github.com/coder/coder/v2/cli/cliui" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
var ( | ||
warnNoMatchedProvisioners=`Your build has been enqueued, but there are no provisioners that accept the required tags. Once a compatible provisioner becomes available, your build will continue. Please contact your administrator. | ||
Details: | ||
Provisioner job ID : %s | ||
Requested tags : %s | ||
` | ||
warnNoAvailableProvisioners=`Provisioners that accept the required tags have not responded for longer than expected. This may delay your build. Please contact your administrator if your build does not complete. | ||
Details: | ||
Provisioner job ID : %s | ||
Requested tags : %s | ||
Most recently seen : %s | ||
` | ||
) | ||
// WarnMatchedProvisioners warns the user if there are no provisioners that | ||
// match the requested tags for a given provisioner job. | ||
// If the job is not pending, it is ignored. | ||
funcWarnMatchedProvisioners(w io.Writer,mp*codersdk.MatchedProvisioners,job codersdk.ProvisionerJob) { | ||
ifmp==nil { | ||
// Nothing in the response, nothing to do here! | ||
return | ||
} | ||
ifjob.Status!=codersdk.ProvisionerJobPending { | ||
// Only warn if the job is pending. | ||
return | ||
} | ||
vartagsJSON strings.Builder | ||
iferr:=json.NewEncoder(&tagsJSON).Encode(job.Tags);err!=nil { | ||
// Fall back to the less-pretty string representation. | ||
tagsJSON.Reset() | ||
_,_=tagsJSON.WriteString(fmt.Sprintf("%v",job.Tags)) | ||
} | ||
ifmp.Count==0 { | ||
cliui.Warnf(w,warnNoMatchedProvisioners,job.ID,tagsJSON.String()) | ||
return | ||
} | ||
ifmp.Available==0 { | ||
cliui.Warnf(w,warnNoAvailableProvisioners,job.ID,strings.TrimSpace(tagsJSON.String()),mp.MostRecentlySeen.Time) | ||
return | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package cliutil_test | ||
import ( | ||
"strings" | ||
"testing" | ||
"github.com/stretchr/testify/require" | ||
"github.com/coder/coder/v2/cli/cliutil" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
funcTestWarnMatchedProvisioners(t*testing.T) { | ||
t.Parallel() | ||
for_,tt:=range []struct { | ||
namestring | ||
mp*codersdk.MatchedProvisioners | ||
job codersdk.ProvisionerJob | ||
expectstring | ||
}{ | ||
{ | ||
name:"no_match", | ||
mp:&codersdk.MatchedProvisioners{ | ||
Count:0, | ||
Available:0, | ||
}, | ||
job: codersdk.ProvisionerJob{ | ||
Status:codersdk.ProvisionerJobPending, | ||
}, | ||
expect:`there are no provisioners that accept the required tags`, | ||
}, | ||
{ | ||
name:"no_available", | ||
mp:&codersdk.MatchedProvisioners{ | ||
Count:1, | ||
Available:0, | ||
}, | ||
job: codersdk.ProvisionerJob{ | ||
Status:codersdk.ProvisionerJobPending, | ||
}, | ||
expect:`Provisioners that accept the required tags have not responded for longer than expected`, | ||
}, | ||
{ | ||
name:"match", | ||
mp:&codersdk.MatchedProvisioners{ | ||
Count:1, | ||
Available:1, | ||
}, | ||
job: codersdk.ProvisionerJob{ | ||
Status:codersdk.ProvisionerJobPending, | ||
}, | ||
}, | ||
{ | ||
name:"not_pending", | ||
mp:&codersdk.MatchedProvisioners{}, | ||
job: codersdk.ProvisionerJob{ | ||
Status:codersdk.ProvisionerJobRunning, | ||
}, | ||
}, | ||
} { | ||
tt:=tt | ||
t.Run(tt.name,func(t*testing.T) { | ||
t.Parallel() | ||
varw strings.Builder | ||
cliutil.WarnMatchedProvisioners(&w,tt.mp,tt.job) | ||
iftt.expect!="" { | ||
require.Contains(t,w.String(),tt.expect) | ||
}else { | ||
require.Empty(t,w.String()) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -245,7 +245,7 @@ func (e *Executor) runOnce(t time.Time) Stats { | ||
} | ||
} | ||
nextBuild, job,_,err = builder.Build(e.ctx, tx, nil, audit.WorkspaceBuildBaggage{IP: "127.0.0.1"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. self-review: we may need to notify or log about this, but deferring for later. | ||
if err != nil { | ||
return xerrors.Errorf("build workspace with transition %q: %w", nextTransition, err) | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -299,7 +299,7 @@ var ( | ||
rbac.ResourceSystem.Type: {policy.WildcardSymbol}, | ||
rbac.ResourceOrganization.Type: {policy.ActionCreate, policy.ActionRead}, | ||
rbac.ResourceOrganizationMember.Type: {policy.ActionCreate, policy.ActionDelete, policy.ActionRead}, | ||
rbac.ResourceProvisionerDaemon.Type: {policy.ActionCreate, policy.ActionRead, policy.ActionUpdate}, | ||
rbac.ResourceProvisionerKeys.Type: {policy.ActionCreate, policy.ActionRead, policy.ActionDelete}, | ||
rbac.ResourceUser.Type: rbac.ResourceUser.AvailableActions(), | ||
rbac.ResourceWorkspaceDormant.Type: {policy.ActionUpdate, policy.ActionDelete, policy.ActionWorkspaceStop}, | ||
@@ -317,6 +317,23 @@ var ( | ||
}), | ||
Scope: rbac.ScopeAll, | ||
}.WithCachedASTValue() | ||
subjectSystemReadProvisionerDaemons = rbac.Subject{ | ||
FriendlyName: "System", | ||
johnstcn marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
ID: uuid.Nil.String(), | ||
Roles: rbac.Roles([]rbac.Role{ | ||
{ | ||
Identifier: rbac.RoleIdentifier{Name: "system-read-provisioner-daemons"}, | ||
DisplayName: "Coder", | ||
Site: rbac.Permissions(map[string][]policy.Action{ | ||
rbac.ResourceProvisionerDaemon.Type: {policy.ActionRead}, | ||
}), | ||
Org: map[string][]rbac.Permission{}, | ||
User: []rbac.Permission{}, | ||
}, | ||
}), | ||
Scope: rbac.ScopeAll, | ||
}.WithCachedASTValue() | ||
) | ||
// AsProvisionerd returns a context with an actor that has permissions required | ||
@@ -359,6 +376,12 @@ func AsSystemRestricted(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, authContextKey{}, subjectSystemRestricted) | ||
} | ||
// AsSystemReadProvisionerDaemons returns a context with an actor that has permissions | ||
// to read provisioner daemons. | ||
func AsSystemReadProvisionerDaemons(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, authContextKey{}, subjectSystemReadProvisionerDaemons) | ||
} | ||
Comment on lines +379 to +384 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. self-review: I wanted to avoid sprinkling | ||
var AsRemoveActor = rbac.Subject{ | ||
ID: "remove-actor", | ||
} | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.