Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Fixed tests and linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: pmahindrakar-oss <[email protected]>
  • Loading branch information
pmahindrakar-oss committed Mar 19, 2021
1 parent 4936d30 commit 832c408
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 154 deletions.
7 changes: 5 additions & 2 deletions cmd/create/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/flyteorg/flytectl/cmd/config"
cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
)
Expand Down Expand Up @@ -109,16 +110,18 @@ var (
func createExecutionCommand(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error {
var execParams *ExecutionParams
var err error
sourceProject := config.GetConfig().Project
sourceDomain := config.GetConfig().Domain
if execParams, err = readConfigAndValidate(); err != nil {
return err
}
var executionRequest *admin.ExecutionCreateRequest
if execParams.isTask {
if executionRequest, err = createExecutionRequestForTask(ctx, execParams.name, cmdCtx); err != nil {
if executionRequest, err = createExecutionRequestForTask(ctx, execParams.name, sourceProject, sourceDomain, cmdCtx); err != nil {
return err
}
} else {
if executionRequest, err = createExecutionRequestForWorkflow(ctx, execParams.name, cmdCtx); err != nil {
if executionRequest, err = createExecutionRequestForWorkflow(ctx, execParams.name, sourceProject, sourceDomain, cmdCtx); err != nil {
return err
}
}
Expand Down
26 changes: 12 additions & 14 deletions cmd/create/execution_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"sigs.k8s.io/yaml"
)

func createExecutionRequestForWorkflow(ctx context.Context, workflowName string, cmdCtx cmdCore.CommandContext) (*admin.ExecutionCreateRequest, error) {
func createExecutionRequestForWorkflow(ctx context.Context, workflowName string, project string, domain string, cmdCtx cmdCore.CommandContext) (*admin.ExecutionCreateRequest, error) {
var lp *admin.LaunchPlan
var err error
// Fetch the task
if lp, err = cmdGet.FetchLPVersionOrLatest(ctx, workflowName, executionConfig.Version, cmdCtx); err != nil {
// Fetch the launch plan
if lp, err = cmdGet.FetchLPVersion(ctx, workflowName, executionConfig.Version, project, domain, cmdCtx); err != nil {
return nil, err
}
// Create workflow params literal map
Expand All @@ -36,11 +36,11 @@ func createExecutionRequestForWorkflow(ctx context.Context, workflowName string,
return createExecutionRequest(ID, inputs, nil), nil
}

func createExecutionRequestForTask(ctx context.Context, taskName string, cmdCtx cmdCore.CommandContext) (*admin.ExecutionCreateRequest, error) {
func createExecutionRequestForTask(ctx context.Context, taskName string, project string, domain string, cmdCtx cmdCore.CommandContext) (*admin.ExecutionCreateRequest, error) {
var task *admin.Task
var err error
// Fetch the task
if task, err = cmdGet.FetchTaskVersionOrLatest(ctx, taskName, executionConfig.Version, cmdCtx); err != nil {
if task, err = cmdGet.FetchTaskVersion(ctx, taskName, executionConfig.Version, project, domain, cmdCtx); err != nil {
return nil, err
}
// Create task variables literal map
Expand All @@ -61,8 +61,8 @@ func createExecutionRequestForTask(ctx context.Context, taskName string, cmdCtx
}
ID := &core.Identifier{
ResourceType: core.ResourceType_TASK,
Project: executionConfig.TargetProject,
Domain: executionConfig.TargetDomain,
Project: project,
Domain: domain,
Name: task.Id.Name,
Version: task.Id.Version,
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func resolveOverrides(readExecutionConfig *ExecutionConfig) {
if executionConfig.TargetDomain != "" {
readExecutionConfig.TargetDomain = executionConfig.TargetDomain
}
// Use the configured project and domain to launch the task/workflow
// Use the root project and domain to launch the task/workflow if target is unspecified
if executionConfig.TargetProject == "" {
readExecutionConfig.TargetProject = config.GetConfig().Project
}
Expand All @@ -133,16 +133,14 @@ func readConfigAndValidate() (*ExecutionParams, error) {
resolveOverrides(readExecutionConfig)
// Update executionConfig pointer to readExecutionConfig as it contains all the updates.
executionConfig = readExecutionConfig

isTask := executionConfig.Task != ""
isWorkflow := executionConfig.Workflow != ""
isTask := readExecutionConfig.Task != ""
isWorkflow := readExecutionConfig.Workflow != ""
if isTask == isWorkflow {
return nil, errors.New("either one of task or workflow name should be specified to launch an execution")
}
name := executionConfig.Task
name := readExecutionConfig.Task
if !isTask {
name = executionConfig.Workflow
name = readExecutionConfig.Workflow
}
return &ExecutionParams{name: name, isTask: isTask}, nil
}

66 changes: 0 additions & 66 deletions cmd/create/executionconfig_flags_test.go

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

4 changes: 2 additions & 2 deletions cmd/get/execution_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func writeExecConfigToFile(executionConfig ExecutionConfig, fileName string) err

func createAndWriteExecConfigForTask(task *admin.Task, fileName string) error {
var err error
executionConfig := ExecutionConfig{Task: task.Id.Name}
executionConfig := ExecutionConfig{Task: task.Id.Name, Version: task.Id.Version}
if executionConfig.Inputs, err = getParamMapForTask(task); err != nil {
return err
}
Expand All @@ -59,7 +59,7 @@ func createAndWriteExecConfigForTask(task *admin.Task, fileName string) error {

func createAndWriteExecConfigForWorkflow(wlp *admin.LaunchPlan, fileName string) error {
var err error
executionConfig := ExecutionConfig{Workflow: wlp.Id.Name}
executionConfig := ExecutionConfig{Workflow: wlp.Id.Name, Version: wlp.Id.Version}
if executionConfig.Inputs, err = getParamMapForWorkflow(wlp); err != nil {
return err
}
Expand Down
26 changes: 19 additions & 7 deletions cmd/get/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
type LaunchPlanConfig struct {
ExecFile string `json:"execFile" pflag:",execution file name to be used for generating execution spec of a single launchplan."`
Version string `json:"version" pflag:",version of the launchplan to be fetched."`
Latest bool `json:"latest" pflag:", flag to indicate to fetch the latest version, version flag will be ignored in this case"`
}

var launchplanColumns = []printer.Column{
Expand All @@ -76,26 +77,37 @@ func LaunchplanToProtoMessages(l []*admin.LaunchPlan) []proto.Message {

func getLaunchPlanFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error {
launchPlanPrinter := printer.Printer{}
project := config.GetConfig().Project
domain := config.GetConfig().Domain
if len(args) == 1 {
name := args[0]
var launchPlans []*admin.LaunchPlan
var err error
// Right only support writing execution file for single task version.
if launchPlanConfig.ExecFile != "" {
var lp *admin.LaunchPlan
if lp, err = FetchLPVersionOrLatest(ctx, name, taskConfig.Version, cmdCtx); err != nil {
var lp *admin.LaunchPlan
if launchPlanConfig.Latest {
if lp, err = fetchLPLatestVersion(ctx, name, project, domain, cmdCtx); err != nil {
return err
}
launchPlans = append(launchPlans, lp)
if err = createAndWriteExecConfigForWorkflow(lp, launchPlanConfig.ExecFile); err != nil {
} else if launchPlanConfig.Version != "" {
if lp, err = FetchLPVersion(ctx, name, launchPlanConfig.Version, project, domain, cmdCtx); err != nil {
return err
}
launchPlans = append(launchPlans, lp)
} else {
launchPlans, err = getAllVerOfLP(ctx, name, cmdCtx)
launchPlans, err = getAllVerOfLP(ctx, name, project, domain, cmdCtx)
if err != nil {
return err
}
}
if launchPlanConfig.ExecFile != "" {
// There would be atleast one launchplan object when code reaches here and hence the length assertion is not required.
lp = launchPlans[0]
// Only write the first task from the tasks object.
if err = createAndWriteExecConfigForWorkflow(lp, launchPlanConfig.ExecFile); err != nil {
return err
}
}
logger.Debugf(ctx, "Retrieved %v launch plans", len(launchPlans))
err = launchPlanPrinter.Print(config.GetConfig().MustOutputFormat(), launchplanColumns, LaunchplanToProtoMessages(launchPlans)...)
if err != nil {
Expand All @@ -104,7 +116,7 @@ func getLaunchPlanFunc(ctx context.Context, args []string, cmdCtx cmdCore.Comman
return nil
}

launchPlans, err := adminutils.GetAllNamedEntities(ctx, cmdCtx.AdminClient().ListLaunchPlanIds, adminutils.ListRequest{Project: config.GetConfig().Project, Domain: config.GetConfig().Domain})
launchPlans, err := adminutils.GetAllNamedEntities(ctx, cmdCtx.AdminClient().ListLaunchPlanIds, adminutils.ListRequest{Project: project, Domain: domain})
if err != nil {
return err
}
Expand Down
55 changes: 26 additions & 29 deletions cmd/get/launch_plan_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"context"
"fmt"

"github.com/flyteorg/flytectl/cmd/config"
cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
)

func getAllVerOfLP(ctx context.Context, lpName string, cmdCtx cmdCore.CommandContext) ([]*admin.LaunchPlan, error) {
func getAllVerOfLP(ctx context.Context, lpName string, project string, domain string, cmdCtx cmdCore.CommandContext) ([]*admin.LaunchPlan, error) {
tList, err := cmdCtx.AdminClient().ListLaunchPlans(ctx, &admin.ResourceListRequest{
Limit: 1,
Id: &admin.NamedEntityIdentifier{
Project: config.GetConfig().Project,
Domain: config.GetConfig().Domain,
Project: project,
Domain: domain,
Name: lpName,
},
SortBy: &admin.Sort{
Key: "created_at",
Direction: admin.Sort_DESCENDING,
},
Limit: 100,
})
if err != nil {
return nil, err
Expand All @@ -32,30 +31,28 @@ func getAllVerOfLP(ctx context.Context, lpName string, cmdCtx cmdCore.CommandCon
return tList.LaunchPlans, nil
}

func FetchLPVersionOrLatest(ctx context.Context, name string, version string, cmdCtx cmdCore.CommandContext) (*admin.LaunchPlan, error) {
var lp *admin.LaunchPlan
var err error
if version == "" {
// Fetch the latest version of the task.
var lpVersions []*admin.LaunchPlan
lpVersions, err = getAllVerOfLP(ctx, name, cmdCtx)
if err != nil {
return nil, err
}
lp = lpVersions[0]
} else {
lp, err = cmdCtx.AdminClient().GetLaunchPlan(ctx, &admin.ObjectGetRequest{
Id: &core.Identifier{
ResourceType: core.ResourceType_LAUNCH_PLAN,
Project: config.GetConfig().Project,
Domain: config.GetConfig().Domain,
Name: name,
Version: version,
},
})
if err != nil {
return nil, err
}
func fetchLPLatestVersion(ctx context.Context, name string, project string, domain string, cmdCtx cmdCore.CommandContext) (*admin.LaunchPlan, error) {
// Fetch the latest version of the task.
lpVersions, err := getAllVerOfLP(ctx, name, project, domain, cmdCtx)
if err != nil {
return nil, err
}
lp := lpVersions[0]
return lp, nil
}

func FetchLPVersion(ctx context.Context, name string, version string, project string, domain string, cmdCtx cmdCore.CommandContext) (*admin.LaunchPlan, error) {
lp, err := cmdCtx.AdminClient().GetLaunchPlan(ctx, &admin.ObjectGetRequest{
Id: &core.Identifier{
ResourceType: core.ResourceType_LAUNCH_PLAN,
Project: project,
Domain: domain,
Name: name,
Version: version,
},
})
if err != nil {
return nil, err
}
return lp, nil
}
1 change: 1 addition & 0 deletions cmd/get/launchplanconfig_flags.go

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

Loading

0 comments on commit 832c408

Please sign in to comment.