Skip to content

fix: return provisioners in desc order and add limit to cli #16720

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 15 additions & 1 deletion cli/provisioners.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (r *RootCmd) provisionerList() *serpent.Command {
cliui.TableFormat([]provisionerDaemonRow{}, []string{"name", "organization", "status", "key name", "created at", "last seen at", "version", "tags"}),
cliui.JSONFormat(),
)
limit int64
)

cmd := &serpent.Command{
Expand All @@ -57,7 +58,9 @@ func (r *RootCmd) provisionerList() *serpent.Command {
return xerrors.Errorf("current organization: %w", err)
}

daemons, err := client.OrganizationProvisionerDaemons(ctx, org.ID, nil)
daemons, err := client.OrganizationProvisionerDaemons(ctx, org.ID, &codersdk.OrganizationProvisionerDaemonsOptions{
Limit: int(limit),
})
if err != nil {
return xerrors.Errorf("list provisioner daemons: %w", err)
}
Expand Down Expand Up @@ -86,6 +89,17 @@ func (r *RootCmd) provisionerList() *serpent.Command {
},
}

cmd.Options = append(cmd.Options, []serpent.Option{
{
Flag: "limit",
FlagShorthand: "l",
Env: "CODER_PROVISIONER_LIST_LIMIT",
Description: "Limit the number of provisioners returned.",
Default: "50",
Value: serpent.Int64Of(&limit),
},
}...)

orgContext.AttachOptions(cmd)
formatter.AttachOptions(&cmd.Options)

Expand Down
3 changes: 3 additions & 0 deletions cli/testdata/coder_provisioner_list_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ OPTIONS:
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default: name,organization,status,key name,created at,last seen at,version,tags)
Columns to display in table output.

-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)
Limit the number of provisioners returned.

-o, --output table|json (default: table)
Output format.

Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,7 @@ func (q *FakeQuerier) GetProvisionerDaemonsWithStatusByOrganization(ctx context.
}

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

if arg.Limit.Valid && arg.Limit.Int32 > 0 && len(rows) > int(arg.Limit.Int32) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/queries.sql.go

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

2 changes: 1 addition & 1 deletion coderd/database/queries/provisionerdaemons.sql
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ WHERE
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 DESC
LIMIT
sqlc.narg('limit')::int;

Expand Down
4 changes: 2 additions & 2 deletions coderd/provisionerdaemons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ func TestProvisionerDaemons(t *testing.T) {
})
require.NoError(t, err)
require.Len(t, daemons, 2)
require.Equal(t, pd1.ID, daemons[0].ID)
require.Equal(t, pd2.ID, daemons[1].ID)
require.Equal(t, pd1.ID, daemons[1].ID)
require.Equal(t, pd2.ID, daemons[0].ID)
})

t.Run("Tags", func(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/cli/provisioner_list.md

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

3 changes: 3 additions & 0 deletions enterprise/cli/testdata/coder_provisioner_list_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ OPTIONS:
-c, --column [id|organization id|created at|last seen at|name|version|api version|tags|key name|status|current job id|current job status|current job template name|current job template icon|current job template display name|previous job id|previous job status|previous job template name|previous job template icon|previous job template display name|organization] (default: name,organization,status,key name,created at,last seen at,version,tags)
Columns to display in table output.

-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)
Limit the number of provisioners returned.

-o, --output table|json (default: table)
Output format.

Expand Down
Loading