Skip to content
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

Fix flytectl returning the oldest workflow when using --latest flag #5716

Merged
merged 4 commits into from
Sep 9, 2024
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
2 changes: 1 addition & 1 deletion flytectl/cmd/get/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func FetchLPForName(ctx context.Context, fetcher ext.AdminFetcherExtInterface, n
var lp *admin.LaunchPlan
var err error
if launchplan.DefaultConfig.Latest {
if lp, err = fetcher.FetchLPLatestVersion(ctx, name, project, domain, launchplan.DefaultConfig.Filter); err != nil {
if lp, err = fetcher.FetchLPLatestVersion(ctx, name, project, domain); err != nil {
return nil, err
}
launchPlans = append(launchPlans, lp)
Expand Down
5 changes: 2 additions & 3 deletions flytectl/cmd/get/launch_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ func TestGetLaunchPlanFuncLatest(t *testing.T) {
defer s.TearDown()
getLaunchPlanSetup()
launchplan.DefaultConfig.Latest = true
launchplan.DefaultConfig.Filter = filters.Filters{}
s.FetcherExt.OnFetchLPLatestVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(launchPlan2, nil)
s.FetcherExt.OnFetchLPLatestVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(launchPlan2, nil)
err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx)
assert.Nil(t, err)
s.FetcherExt.AssertCalled(t, "FetchLPLatestVersion", s.Ctx, "launchplan1", projectValue, domainValue, launchplan.DefaultConfig.Filter)
s.FetcherExt.AssertCalled(t, "FetchLPLatestVersion", s.Ctx, "launchplan1", projectValue, domainValue)
s.TearDownAndVerify(t, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"generic": {"var": {"type": {"simple": "STRUCT"},"description": "generic"},"default": {"scalar": {"generic": {"foo": "foo"}}}},"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"generic": {"var": {"type": {"simple": "STRUCT"},"description": "generic"},"default": {"scalar": {"generic": {"foo": "foo"}}}},"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`)
}

Expand Down
2 changes: 1 addition & 1 deletion flytectl/cmd/get/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func FetchWorkflowForName(ctx context.Context, fetcher ext.AdminFetcherExtInterf
domain string) (workflows []*admin.Workflow, isList bool, err error) {
var workflow *admin.Workflow
if workflowconfig.DefaultConfig.Latest {
if workflow, err = fetcher.FetchWorkflowLatestVersion(ctx, name, project, domain, workflowconfig.DefaultConfig.Filter); err != nil {
if workflow, err = fetcher.FetchWorkflowLatestVersion(ctx, name, project, domain); err != nil {
return nil, false, err
}
workflows = append(workflows, workflow)
Expand Down
3 changes: 1 addition & 2 deletions flytectl/cmd/get/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ func TestGetWorkflowFuncLatestWithTable(t *testing.T) {

getWorkflowSetup()
workflow.DefaultConfig.Latest = true
workflow.DefaultConfig.Filter = filters.Filters{}
config.GetConfig().Output = printer.OutputFormatTABLE.String()
s.FetcherExt.OnFetchWorkflowLatestVersionMatch(s.Ctx, "workflow1", projectValue, domainValue, filters.Filters{}).Return(workflow1, nil)
s.FetcherExt.OnFetchWorkflowLatestVersionMatch(s.Ctx, "workflow1", projectValue, domainValue).Return(workflow1, nil)
err := getWorkflowFunc(s.Ctx, argsWf, s.CmdCtx)
assert.Nil(t, err)
s.TearDownAndVerify(t, `
Expand Down
4 changes: 2 additions & 2 deletions flytectl/pkg/ext/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type AdminFetcherExtInterface interface {
FetchAllVerOfLP(ctx context.Context, lpName, project, domain string, filter filters.Filters) ([]*admin.LaunchPlan, error)

// FetchLPLatestVersion fetches latest version of launch plan in a project, domain
FetchLPLatestVersion(ctx context.Context, name, project, domain string, filter filters.Filters) (*admin.LaunchPlan, error)
FetchLPLatestVersion(ctx context.Context, name, project, domain string) (*admin.LaunchPlan, error)

// FetchLPVersion fetches particular version of launch plan in a project, domain
FetchLPVersion(ctx context.Context, name, version, project, domain string) (*admin.LaunchPlan, error)
Expand All @@ -55,7 +55,7 @@ type AdminFetcherExtInterface interface {
FetchAllVerOfWorkflow(ctx context.Context, name, project, domain string, filter filters.Filters) ([]*admin.Workflow, error)

// FetchWorkflowLatestVersion fetches latest version of workflow in a project, domain
FetchWorkflowLatestVersion(ctx context.Context, name, project, domain string, filter filters.Filters) (*admin.Workflow, error)
FetchWorkflowLatestVersion(ctx context.Context, name, project, domain string) (*admin.Workflow, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the filter here? What if I want to fetch the latest workflow with a specific tag?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think better to remove it actually, it's clearer in what it's doing, and merging filters behind the scenes seems weird to me.


// FetchWorkflowVersion fetches particular version of workflow in a project, domain
FetchWorkflowVersion(ctx context.Context, name, version, project, domain string) (*admin.Workflow, error)
Expand Down
9 changes: 7 additions & 2 deletions flytectl/pkg/ext/launch_plan_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ func (a *AdminFetcherExtClient) FetchAllVerOfLP(ctx context.Context, lpName, pro
}

// FetchLPLatestVersion fetches latest version for give launch plan name
func (a *AdminFetcherExtClient) FetchLPLatestVersion(ctx context.Context, name, project, domain string, filter filters.Filters) (*admin.LaunchPlan, error) {
// Fetch the latest version of the task.
func (a *AdminFetcherExtClient) FetchLPLatestVersion(ctx context.Context, name, project, domain string) (*admin.LaunchPlan, error) {
// Fetch the latest version of the LaunchPLan.
filter := filters.Filters{
SortBy: "created_at",
Limit: 1,
Asc: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure if I need to specify Asc but better safe than sorry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better be explicit yeah

}
lpVersions, err := a.FetchAllVerOfLP(ctx, name, project, domain, filter)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions flytectl/pkg/ext/launch_plan_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ func TestFetchAllVerOfLPEmptyResponse(t *testing.T) {
func TestFetchLPLatestVersion(t *testing.T) {
getLaunchPlanFetcherSetup()
adminClient.OnListLaunchPlansMatch(mock.Anything, mock.Anything).Return(launchPlanListResponse, nil)
_, err := adminFetcherExt.FetchLPLatestVersion(ctx, "lpName", "project", "domain", lpFilters)
_, err := adminFetcherExt.FetchLPLatestVersion(ctx, "lpName", "project", "domain")
assert.Nil(t, err)
}

func TestFetchLPLatestVersionError(t *testing.T) {
launchPlanListResponse := &admin.LaunchPlanList{}
getLaunchPlanFetcherSetup()
adminClient.OnListLaunchPlansMatch(mock.Anything, mock.Anything).Return(launchPlanListResponse, nil)
_, err := adminFetcherExt.FetchLPLatestVersion(ctx, "lpName", "project", "domain", lpFilters)
_, err := adminFetcherExt.FetchLPLatestVersion(ctx, "lpName", "project", "domain")
assert.Equal(t, fmt.Errorf("no launchplans retrieved for lpName"), err)
}
36 changes: 18 additions & 18 deletions flytectl/pkg/ext/mocks/admin_fetcher_ext_interface.go

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

7 changes: 6 additions & 1 deletion flytectl/pkg/ext/workflow_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ func (a *AdminFetcherExtClient) FetchAllWorkflows(ctx context.Context, project,
}

// FetchWorkflowLatestVersion fetches latest version for given workflow name
func (a *AdminFetcherExtClient) FetchWorkflowLatestVersion(ctx context.Context, name, project, domain string, filter filters.Filters) (*admin.Workflow, error) {
func (a *AdminFetcherExtClient) FetchWorkflowLatestVersion(ctx context.Context, name, project, domain string) (*admin.Workflow, error) {
// Fetch the latest version of the workflow.
filter := filters.Filters{
SortBy: "created_at",
Limit: 1,
Asc: false,
}
wVersions, err := a.FetchAllVerOfWorkflow(ctx, name, project, domain, filter)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions flytectl/pkg/ext/workflow_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ func TestFetchWorkflowLatestVersion(t *testing.T) {
getWorkflowFetcherSetup()
adminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(workflowResponse, nil)
adminClient.OnListWorkflowsMatch(mock.Anything, mock.Anything).Return(workflowListResponse, nil)
_, err := adminFetcherExt.FetchWorkflowLatestVersion(ctx, "workflowName", "project", "domain", workflowFilter)
_, err := adminFetcherExt.FetchWorkflowLatestVersion(ctx, "workflowName", "project", "domain")
assert.Nil(t, err)
}

func TestFetchWorkflowLatestVersionError(t *testing.T) {
workflowListResponse := &admin.WorkflowList{}
getWorkflowFetcherSetup()
adminClient.OnListWorkflowsMatch(mock.Anything, mock.Anything).Return(workflowListResponse, nil)
_, err := adminFetcherExt.FetchWorkflowLatestVersion(ctx, "workflowName", "project", "domain", workflowFilter)
_, err := adminFetcherExt.FetchWorkflowLatestVersion(ctx, "workflowName", "project", "domain")
assert.Equal(t, fmt.Errorf("no workflow retrieved for workflowName"), err)
}
Loading