Skip to content

Commit

Permalink
#minor feat: pagination support for get commands (#234)
Browse files Browse the repository at this point in the history
* feat: pagination support for get commands

Signed-off-by: Nishant Mittal <[email protected]>
  • Loading branch information
nishantwrp authored Dec 11, 2021
1 parent 325b106 commit 2766c18
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 30 deletions.
1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/execution/config_flags.go

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

14 changes: 14 additions & 0 deletions flytectl/cmd/config/subcommand/execution/config_flags_test.go

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

1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/launchplan/config_flags.go

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

14 changes: 14 additions & 0 deletions flytectl/cmd/config/subcommand/launchplan/config_flags_test.go

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

1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/project/config_flags.go

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

14 changes: 14 additions & 0 deletions flytectl/cmd/config/subcommand/project/config_flags_test.go

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

1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/task/config_flags.go

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

14 changes: 14 additions & 0 deletions flytectl/cmd/config/subcommand/task/config_flags_test.go

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

1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/workflow/config_flags.go

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

14 changes: 14 additions & 0 deletions flytectl/cmd/config/subcommand/workflow/config_flags_test.go

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

14 changes: 9 additions & 5 deletions flytectl/cmd/get/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ Retrieve executions by name within the project and domain:
Retrieve all the executions with filters:
::
flytectl get execution -p flytesnacks -d development --filter.fieldSelector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200"
flytectl get execution -p flytesnacks -d development --filter.fieldSelector="execution.phase in (FAILED;SUCCEEDED),execution.duration<200"
Retrieve executions as per the specified limit and sorting parameters:
::
flytectl get execution -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc
Retrieves all the executions on other pages.
::
flytectl get -p flytesnacks -d development execution --filter.limit=10 --filter.page=2
Retrieve executions within the project and domain in YAML format:
Expand Down
18 changes: 11 additions & 7 deletions flytectl/cmd/get/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ Retrieve a particular version of the launch plan by name within the project and
Retrieve all the launch plans with filters:
::
flytectl get launchplan -p flytesnacks -d development --filter.fieldSelector="name=core.basic.lp.go_greet"
Retrieve launch plans entity search across all versions with filters:
::
flytectl get launchplan -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="version=v1"
Retrieve all the launch plans with limit and sorting:
::
flytectl get launchplan -p flytesnacks -d development --filter.sortBy=created_at --filter.limit=1 --filter.asc
Retrieves all the launch plans on other pages.
::
flytectl get -p flytesnacks -d development launchplan --filter.limit=10 --filter.page=2
Retrieve all launch plans within the project and domain in YAML format:
Expand Down
11 changes: 8 additions & 3 deletions flytectl/cmd/get/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ Retrieve project by name:
Retrieve all the projects with filters:
::
flytectl get project --filter.fieldSelector="project.name=flytesnacks"
Retrieve all the projects with limit and sorting:
::
flytectl get project --filter.sortBy=created_at --filter.limit=1 --filter.asc
Retrieves all the projects on other pages.
::
flytectl get project --filter.limit=10 --filter.page=2
Retrieve all the projects in yaml format:
::
Expand Down
19 changes: 12 additions & 7 deletions flytectl/cmd/get/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ Retrieve particular version of task by name within project and domain:
Retrieve all the tasks with filters:
::
flytectl get task -p flytesnacks -d development --filter.fieldSelector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1"
flytectl get task -p flytesnacks -d development --filter.fieldSelector="task.name=k8s_spark.pyspark_pi.print_every_time,task.version=v1"
Retrieve a specific task with filters:
::
flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.fieldSelector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z"
flytectl get task -p flytesnacks -d development k8s_spark.pyspark_pi.print_every_time --filter.fieldSelector="task.version=v1,created_at>=2021-05-24T21:43:12.325335Z"
Retrieve all the tasks with limit and sorting:
::
flytectl get -p flytesnacks -d development task --filter.sortBy=created_at --filter.limit=1 --filter.asc
Retrieves all the task on other pages.
::
flytectl get -p flytesnacks -d development task --filter.limit=10 --filter.page=2
Retrieve all the tasks within project and domain in yaml format:
::
Expand Down
15 changes: 10 additions & 5 deletions flytectl/cmd/get/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,24 @@ Retrieve particular version of workflow by name within project and domain:
Retrieve all the workflows with filters:
::
flytectl get workflow -p flytesnacks -d development --filter.fieldSelector="workflow.name=k8s_spark.dataframe_passing.my_smart_schema"
Retrieve specific workflow with filters:
::
flytectl get workflow -p flytesnacks -d development k8s_spark.dataframe_passing.my_smart_schema --filter.fieldSelector="workflow.version=v1"
Retrieve all the workflows with limit and sorting:
::
flytectl get -p flytesnacks -d development workflow --filter.sortBy=created_at --filter.limit=1 --filter.asc
Retrieves all the workflows on other pages.
::
flytectl get -p flytesnacks -d development workflow --filter.limit=10 --filter.page 2
Retrieve all the workflows within project and domain in yaml format:
::
Expand Down
7 changes: 4 additions & 3 deletions flytectl/pkg/filters/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var (
DefaultLimit int32 = 100
DefaultFilter = Filters{
Limit: DefaultLimit,
Page: 1,
SortBy: "created_at",
Asc: false,
}
Expand All @@ -12,7 +13,7 @@ var (
type Filters struct {
FieldSelector string `json:"fieldSelector" pflag:",Specifies the Field selector"`
SortBy string `json:"sortBy" pflag:",Specifies which field to sort results "`
// TODO: Support paginated queries
Limit int32 `json:"limit" pflag:",Specifies the limit"`
Asc bool `json:"asc" pflag:",Specifies the sorting order. By default flytectl sort result in descending order"`
Limit int32 `json:"limit" pflag:",Specifies the limit"`
Asc bool `json:"asc" pflag:",Specifies the sorting order. By default flytectl sort result in descending order"`
Page int32 `json:"page" pflag:",Specifies the page number, in case there are multiple pages of results"`
}
12 changes: 12 additions & 0 deletions flytectl/pkg/filters/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package filters

import (
"strconv"

"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
)

Expand All @@ -11,6 +13,7 @@ func BuildResourceListRequestWithName(c Filters, project, domain, name string) (
}
request := &admin.ResourceListRequest{
Limit: uint32(c.Limit),
Token: getToken(c),
Filters: fieldSelector,
Id: &admin.NamedEntityIdentifier{
Project: project,
Expand All @@ -33,6 +36,7 @@ func BuildProjectListRequest(c Filters) (*admin.ProjectListRequest, error) {
}
request := &admin.ProjectListRequest{
Limit: uint32(c.Limit),
Token: getToken(c),
Filters: fieldSelector,
SortBy: buildSortingRequest(c),
}
Expand All @@ -52,3 +56,11 @@ func buildSortingRequest(c Filters) *admin.Sort {
}
return nil
}

func getToken(c Filters) string {
token := int(c.Page-1) * int(c.Limit)
if token <= 0 {
return ""
}
return strconv.Itoa(token)
}
3 changes: 3 additions & 0 deletions flytectl/pkg/filters/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ func TestProjectListRequestFunc(t *testing.T) {
config.GetConfig().Domain = domain
filter := Filters{
Limit: 100,
Page: 2,
SortBy: "created_at",
}
request, err := BuildProjectListRequest(filter)
expectedResponse := &admin.ProjectListRequest{
Limit: 100,
Token: "100",
Filters: "",
SortBy: &admin.Sort{
Key: "created_at",
Expand Down Expand Up @@ -80,6 +82,7 @@ func TestListRequestWithNameFunc(t *testing.T) {
filter := Filters{
Limit: 100,
SortBy: "created_at",
Page: 1,
}
request, err := BuildResourceListRequestWithName(filter, project, domain, name)
expectedResponse := &admin.ResourceListRequest{
Expand Down

0 comments on commit 2766c18

Please sign in to comment.