Skip to content

Commit 208b9eb

Browse files
committed
provisionerd/runner: use Options struct
1 parent e317d53 commit 208b9eb

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

docs/admin/quotas.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Quotas
22

3-
Coder Enterprise admins may define deployment-level quotas to protect against
4-
Denial-of-Service, control costs, and ensure equitable access to cloud resources.
3+
Coder Enterprise admins may define deployment-level quotas to control costs
4+
and ensure equitable access to cloud resources.
55

6-
The quota is enabled by either the `CODER_USER_WORKSPACE_QUOTA`
7-
environment variable or the `--user-workspace-quota` flag. For example,
8-
you may limit each user in a deployment to 5 workspaces like so:
6+
Quotas are available to any license with support for [Groups](./groups.md).
97

10-
```bash
11-
coder server --user-workspace-quota=5
12-
```
8+
Templates describe their quota cost through [`resource_metadata`](../templates/resource-metadata.md).
9+
10+
Coder checks for Quota availability on workspace create, start, and stop
11+
operations.
12+
13+
When a user creates a workspace, the `resource_metadata.cost` fields are summed up,
1314

1415
Then, when users create workspaces they would see:
1516

provisionerd/provisionerd.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,17 @@ func (p *Server) acquireJob(ctx context.Context) {
322322
p.activeJob = runner.New(
323323
ctx,
324324
job,
325-
p,
326-
p.opts.Logger,
327-
p.opts.Filesystem,
328-
p.opts.WorkDirectory,
329-
provisioner,
330-
p.opts.UpdateInterval,
331-
p.opts.ForceCancelInterval,
332-
p.opts.LogBufferInterval,
333-
p.tracer,
334-
p.opts.Metrics.Runner,
325+
runner.Options{
326+
Logger: p.opts.Logger,
327+
Filesystem: p.opts.Filesystem,
328+
WorkDirectory: p.opts.WorkDirectory,
329+
Provisioner: provisioner,
330+
UpdateInterval: p.opts.UpdateInterval,
331+
ForceCancelInterval: p.opts.ForceCancelInterval,
332+
LogDebounceInterval: p.opts.LogBufferInterval,
333+
Tracer: p.tracer,
334+
Metrics: p.opts.Metrics.Runner,
335+
},
335336
)
336337

337338
go p.activeJob.Run()

provisionerd/runner/runner.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,23 @@ type JobUpdater interface {
8686
CompleteJob(ctx context.Context, in *proto.CompletedJob) error
8787
}
8888

89+
type Options struct {
90+
Updater JobUpdater
91+
Logger slog.Logger
92+
Filesystem afero.Fs
93+
WorkDirectory string
94+
Provisioner sdkproto.DRPCProvisionerClient
95+
UpdateInterval time.Duration
96+
ForceCancelInterval time.Duration
97+
LogDebounceInterval time.Duration
98+
Tracer trace.Tracer
99+
Metrics Metrics
100+
}
101+
89102
func New(
90103
ctx context.Context,
91104
job *proto.AcquiredJob,
92-
updater JobUpdater,
93-
logger slog.Logger,
94-
filesystem afero.Fs,
95-
workDirectory string,
96-
provisioner sdkproto.DRPCProvisionerClient,
97-
updateInterval time.Duration,
98-
forceCancelInterval time.Duration,
99-
logDebounceInterval time.Duration,
100-
tracer trace.Tracer,
101-
metrics Metrics,
105+
opts Options,
102106
) *Runner {
103107
m := new(sync.Mutex)
104108

@@ -107,17 +111,17 @@ func New(
107111
gracefulContext, cancelFunc := context.WithCancel(forceStopContext)
108112

109113
return &Runner{
110-
tracer: tracer,
111-
metrics: metrics,
114+
tracer: opts.Tracer,
115+
metrics: opts.Metrics,
112116
job: job,
113-
sender: updater,
114-
logger: logger.With(slog.F("job_id", job.JobId)),
115-
filesystem: filesystem,
116-
workDirectory: workDirectory,
117-
provisioner: provisioner,
118-
updateInterval: updateInterval,
119-
forceCancelInterval: forceCancelInterval,
120-
logBufferInterval: logDebounceInterval,
117+
sender: opts.Updater,
118+
logger: opts.Logger.With(slog.F("job_id", job.JobId)),
119+
filesystem: opts.Filesystem,
120+
workDirectory: opts.WorkDirectory,
121+
provisioner: opts.Provisioner,
122+
updateInterval: opts.UpdateInterval,
123+
forceCancelInterval: opts.ForceCancelInterval,
124+
logBufferInterval: opts.LogDebounceInterval,
121125
queuedLogs: make([]*proto.Log, 0),
122126
mutex: m,
123127
cond: sync.NewCond(m),

0 commit comments

Comments
 (0)