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

Commitad5e678

Browse files
author
Rafael Rodriguez
authored
feat: add filtering options to provisioners list (#19378)
## SummaryIn this pull request we're adding support for additional filteringoptions to the `provisioners list` CLI command and the`/provisionerdaemons` API endpoint.Resolves:#18783### Changes#### Added CLI Options- `--show-offline`: When this option is provided, all provisionerdaemons will be returned. This means that when `--show-offline` is notprovided only `idle` and `busy` provisioner daemons will be returned.- `--status=<list_of_statuses>`: When this option is provided with acomma-separated list of valid statuses (`idle`, `busy`, or `offline`)only provisioner daemons that have these statuses will be returned.- `--max-age=<duration>`: When this option is provided with a validduration value (e.g., `24h`, `30s`) only provisioner daemons with a`last_seen_at` timestamp within the provided max age will be returned.#### Query Params- `?offline=true`: Include offline provisioner daemons in the results.Offline provisioner daemons will be excluded if `?offline=false` or ifoffline is not provided.- `?status=<list_of_statuses>`: Include provisioner daemons with thespecified statuses.- `?max_age=<duration>`: Include provisioner daemons with a`last_seen_at` timestamp within the max age duration.#### Frontend- Since offline provisioners will not be returned by default anymore(`--show-offline` has to be provided to see them), a checkbox was addedto the provisioners list page to allow for offline provisioners to bedisplayed- A revamp of the provisioners page will be done in:#17156, this checkbox change wasjust added to maintain currently functionality with the backend updatesCurrent provisioners page (without checkbox)<img width="1329" height="574" alt="Screenshot 2025-08-20 at 10 5100 AM"src="https://github.com/user-attachments/assets/77b73650-0b62-44f0-a77f-acbe5710809f"/>Provisioners page with checkbox (unchecked)<img width="1314" height="626" alt="Screenshot 2025-08-20 at 10 4840 AM"src="https://github.com/user-attachments/assets/7ba164ad-6d3f-417b-bd39-338c0161b145"/>Provisioner page with checkbox (checked) and URL updated with queryparameters<img width="1306" height="597" alt="Screenshot 2025-08-20 at 10 5014 AM"src="https://github.com/user-attachments/assets/e78d0986-bbf8-491b-9d56-b682973237a0"/>### Show Offline vs Offline StatusTo list offline provisioner daemons, users can either:1. Include the `--show-offline` optionOR2. Include `offline` in the list of values provided to the `--status`option
1 parentd77c3d0 commitad5e678

File tree

25 files changed

+707
-94
lines changed

25 files changed

+707
-94
lines changed

‎cli/provisioners.go‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package cli
22

33
import (
44
"fmt"
5+
"time"
56

67
"golang.org/x/xerrors"
78

89
"github.com/coder/coder/v2/cli/cliui"
10+
"github.com/coder/coder/v2/coderd/util/slice"
911
"github.com/coder/coder/v2/codersdk"
1012
"github.com/coder/serpent"
1113
)
@@ -39,7 +41,10 @@ func (r *RootCmd) provisionerList() *serpent.Command {
3941
cliui.TableFormat([]provisionerDaemonRow{}, []string{"created at","last seen at","key name","name","version","status","tags"}),
4042
cliui.JSONFormat(),
4143
)
42-
limitint64
44+
limitint64
45+
offlinebool
46+
status []string
47+
maxAge time.Duration
4348
)
4449

4550
cmd:=&serpent.Command{
@@ -59,7 +64,10 @@ func (r *RootCmd) provisionerList() *serpent.Command {
5964
}
6065

6166
daemons,err:=client.OrganizationProvisionerDaemons(ctx,org.ID,&codersdk.OrganizationProvisionerDaemonsOptions{
62-
Limit:int(limit),
67+
Limit:int(limit),
68+
Offline:offline,
69+
Status: slice.StringEnums[codersdk.ProvisionerDaemonStatus](status),
70+
MaxAge:maxAge,
6371
})
6472
iferr!=nil {
6573
returnxerrors.Errorf("list provisioner daemons: %w",err)
@@ -98,6 +106,27 @@ func (r *RootCmd) provisionerList() *serpent.Command {
98106
Default:"50",
99107
Value:serpent.Int64Of(&limit),
100108
},
109+
{
110+
Flag:"show-offline",
111+
FlagShorthand:"f",
112+
Env:"CODER_PROVISIONER_SHOW_OFFLINE",
113+
Description:"Show offline provisioners.",
114+
Value:serpent.BoolOf(&offline),
115+
},
116+
{
117+
Flag:"status",
118+
FlagShorthand:"s",
119+
Env:"CODER_PROVISIONER_LIST_STATUS",
120+
Description:"Filter by provisioner status.",
121+
Value:serpent.EnumArrayOf(&status,slice.ToStrings(codersdk.ProvisionerDaemonStatusEnums())...),
122+
},
123+
{
124+
Flag:"max-age",
125+
FlagShorthand:"m",
126+
Env:"CODER_PROVISIONER_LIST_MAX_AGE",
127+
Description:"Filter provisioners by maximum age.",
128+
Value:serpent.DurationOf(&maxAge),
129+
},
101130
}...)
102131

103132
orgContext.AttachOptions(cmd)

‎cli/provisioners_test.go‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,74 @@ func TestProvisioners_Golden(t *testing.T) {
197197
clitest.TestGoldenFile(t,t.Name(),got.Bytes(),replace)
198198
})
199199

200+
t.Run("list with offline provisioner daemons",func(t*testing.T) {
201+
t.Parallel()
202+
203+
vargot bytes.Buffer
204+
inv,root:=clitest.New(t,
205+
"provisioners",
206+
"list",
207+
"--show-offline",
208+
)
209+
inv.Stdout=&got
210+
clitest.SetupConfig(t,templateAdminClient,root)
211+
err:=inv.Run()
212+
require.NoError(t,err)
213+
214+
clitest.TestGoldenFile(t,t.Name(),got.Bytes(),replace)
215+
})
216+
217+
t.Run("list provisioner daemons by status",func(t*testing.T) {
218+
t.Parallel()
219+
220+
vargot bytes.Buffer
221+
inv,root:=clitest.New(t,
222+
"provisioners",
223+
"list",
224+
"--status=idle,offline,busy",
225+
)
226+
inv.Stdout=&got
227+
clitest.SetupConfig(t,templateAdminClient,root)
228+
err:=inv.Run()
229+
require.NoError(t,err)
230+
231+
clitest.TestGoldenFile(t,t.Name(),got.Bytes(),replace)
232+
})
233+
234+
t.Run("list provisioner daemons without offline",func(t*testing.T) {
235+
t.Parallel()
236+
237+
vargot bytes.Buffer
238+
inv,root:=clitest.New(t,
239+
"provisioners",
240+
"list",
241+
"--status=idle,busy",
242+
)
243+
inv.Stdout=&got
244+
clitest.SetupConfig(t,templateAdminClient,root)
245+
err:=inv.Run()
246+
require.NoError(t,err)
247+
248+
clitest.TestGoldenFile(t,t.Name(),got.Bytes(),replace)
249+
})
250+
251+
t.Run("list provisioner daemons by max age",func(t*testing.T) {
252+
t.Parallel()
253+
254+
vargot bytes.Buffer
255+
inv,root:=clitest.New(t,
256+
"provisioners",
257+
"list",
258+
"--max-age=1h",
259+
)
260+
inv.Stdout=&got
261+
clitest.SetupConfig(t,templateAdminClient,root)
262+
err:=inv.Run()
263+
require.NoError(t,err)
264+
265+
clitest.TestGoldenFile(t,t.Name(),got.Bytes(),replace)
266+
})
267+
200268
// Test jobs list with template admin as members are currently
201269
// unable to access provisioner jobs. In the future (with RBAC
202270
// changes), we may allow them to view _their_ jobs.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
ID CREATED AT LAST SEEN AT NAME VERSION TAGS KEY NAME STATUS CURRENT JOB ID CURRENT JOB STATUS PREVIOUS JOB ID PREVIOUS JOB STATUS ORGANIZATION
2-
00000000-0000-0000-aaaa-000000000000 ====[timestamp]===== ====[timestamp]===== default-provisioner v0.0.0-devel map[owner: scope:organization] built-in idle <nil> <nil> 00000000-0000-0000-bbbb-000000000001 succeeded Coder
3-
00000000-0000-0000-aaaa-000000000001 ====[timestamp]===== ====[timestamp]===== provisioner-1 v0.0.0 map[foo:bar owner: scope:organization] built-in busy 00000000-0000-0000-bbbb-000000000002 running <nil> <nil> Coder
4-
00000000-0000-0000-aaaa-000000000002 ====[timestamp]===== ====[timestamp]===== provisioner-2 v0.0.0 map[owner: scope:organization] built-in offline <nil> <nil> 00000000-0000-0000-bbbb-000000000003 succeeded Coder
5-
00000000-0000-0000-aaaa-000000000003 ====[timestamp]===== ====[timestamp]===== provisioner-3 v0.0.0 map[owner: scope:organization] built-in idle <nil> <nil> <nil> <nil> Coder
1+
ID CREATED AT LAST SEEN AT NAME VERSION TAGS KEY NAME STATUS CURRENT JOB ID CURRENT JOB STATUS PREVIOUS JOB ID PREVIOUS JOB STATUS ORGANIZATION
2+
00000000-0000-0000-aaaa-000000000000 ====[timestamp]===== ====[timestamp]===== default-provisioner v0.0.0-devel map[owner: scope:organization] built-in idle <nil> <nil> 00000000-0000-0000-bbbb-000000000001 succeeded Coder
3+
00000000-0000-0000-aaaa-000000000001 ====[timestamp]===== ====[timestamp]===== provisioner-1 v0.0.0 map[foo:bar owner: scope:organization] built-in busy 00000000-0000-0000-bbbb-000000000002 running <nil> <nil> Coder
4+
00000000-0000-0000-aaaa-000000000003 ====[timestamp]===== ====[timestamp]===== provisioner-3 v0.0.0 map[owner: scope:organization] built-in idle <nil> <nil> <nil> <nil> Coder
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-2 v0.0.0 offline map[owner: scope:organization]
5+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-2 v0.0.0 offline map[owner: scope:organization]
5+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]

‎cli/testdata/coder_provisioner_list_--help.golden‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ OPTIONS:
1717
-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)
1818
Limit the number of provisioners returned.
1919

20+
-m, --max-age duration, $CODER_PROVISIONER_LIST_MAX_AGE
21+
Filter provisioners by maximum age.
22+
2023
-o, --output table|json (default: table)
2124
Output format.
2225

26+
-f, --show-offline bool, $CODER_PROVISIONER_SHOW_OFFLINE
27+
Show offline provisioners.
28+
29+
-s, --status [offline|idle|busy], $CODER_PROVISIONER_LIST_STATUS
30+
Filter by provisioner status.
31+
2332
———
2433
Run `coder --help` for a list of global options.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp