Skip to content

Commit

Permalink
Added version support to workflow command (#64)
Browse files Browse the repository at this point in the history
Signed-off-by: Ketan Umare <[email protected]>
  • Loading branch information
pmahindrakar-oss authored May 11, 2021
1 parent 661de8d commit 36c1e4f
Show file tree
Hide file tree
Showing 23 changed files with 749 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ import (
// The shadow config is not using ProjectDomainAttribute/Workflowattribute directly inorder to simplify the inputs.
// As the same structure is being used for both ProjectDomainAttribute/Workflowattribute
type TaskResourceAttrFileConfig struct {
Project string `json:"project"`
Domain string `json:"domain"`
Workflow string `json:"workflow,omitempty"`
Project string
Domain string
Workflow string
*admin.TaskResourceAttributes
}

// WriteConfigToFile used for marshaling the config to a file which can then be used for update/delete
func (t TaskResourceAttrFileConfig) WriteConfigToFile(fileName string) error {
d, err := yaml.Marshal(t)
if err != nil {
return fmt.Errorf("error: %v", err)
fmt.Printf("error: %v", err)
}
if _, err = os.Stat(fileName); err == nil {
if !cmdUtil.AskForConfirmation(fmt.Sprintf("warning file %v will be overwritten", fileName)) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (t TaskResourceAttrFileConfig) DumpTaskResourceAttr(ctx context.Context, fi
logger.Warnf(ctx, "error dumping in file due to %v", err)
return
}
fmt.Printf("wrote the config to file %v", fileName)
fmt.Printf("written the config to file %v", fileName)
} else {
fmt.Printf("%v", t)
}
Expand Down
13 changes: 13 additions & 0 deletions flytectl/cmd/config/subcommand/workflow_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package subcommand

//go:generate pflags WorkflowConfig --default-var DefaultWorklfowConfig

var (
DefaultWorklfowConfig = &WorkflowConfig{}
)

// WorkflowConfig commandline configuration
type WorkflowConfig struct {
Version string `json:"version" pflag:",version of the workflow to be fetched."`
Latest bool `json:"latest" pflag:", flag to indicate to fetch the latest version, version flag will be ignored in this case"`
}
47 changes: 47 additions & 0 deletions flytectl/cmd/config/subcommand/workflowconfig_flags.go

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

146 changes: 146 additions & 0 deletions flytectl/cmd/config/subcommand/workflowconfig_flags_test.go

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

7 changes: 4 additions & 3 deletions flytectl/cmd/delete/matchable_task_resource_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Here the command delete task resource attributes for project flytectldemo and d
flytectl delete task-resource-attribute -p flytectldemo -d development
Deleting task resource attribute using config file which was used for creating it.
Deleting task resource attribute using config file
Here the command deletes task resource attributes from the config file tra.yaml
eg: content of tra.yaml which will use the project domain and workflow name for deleting the resource
Expand All @@ -33,8 +33,9 @@ eg: content of tra.yaml which will use the project domain and workflow name for
.. code-block:: yaml
domain: development
project: flytectldemo
Domain: development
Project: flytectldemo
Workflow: ""
defaults:
cpu: "1"
memory: 150Mi
Expand Down
2 changes: 1 addition & 1 deletion flytectl/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func CreateGetCommand() *cobra.Command {
"task": {CmdFunc: getTaskFunc, Aliases: []string{"tasks"}, Short: taskShort,
Long: taskLong, PFlagProvider: taskConfig},
"workflow": {CmdFunc: getWorkflowFunc, Aliases: []string{"workflows"}, Short: workflowShort,
Long: workflowLong},
Long: workflowLong, PFlagProvider: subcommand.DefaultWorklfowConfig},
"launchplan": {CmdFunc: getLaunchPlanFunc, Aliases: []string{"launchplans"}, Short: launchPlanShort,
Long: launchPlanLong, PFlagProvider: launchPlanConfig},
"execution": {CmdFunc: getExecutionFunc, Aliases: []string{"executions"}, Short: executionShort,
Expand Down
13 changes: 13 additions & 0 deletions flytectl/cmd/get/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ Retrieves launch plan by name within project and domain.
flytectl get launchplan -p flytesnacks -d development core.basic.lp.go_greet
Retrieves latest version of task by name within project and domain.
::
flytectl get launchplan -p flytesnacks -d development core.basic.lp.go_greet --latest
Retrieves particular version of launchplan by name within project and domain.
::
flytectl get launchplan -p flytesnacks -d development core.basic.lp.go_greet --version v2
Retrieves launchplan by filters.
::
Expand Down
11 changes: 7 additions & 4 deletions flytectl/cmd/get/matchable_task_resource_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ eg: content of tra.yaml
.. code-block:: yaml
domain: development
project: flytectldemo
Domain: development
Project: flytectldemo
Workflow: ""
defaults:
cpu: "1"
memory: 150Mi
Expand Down Expand Up @@ -72,10 +73,11 @@ func getTaskResourceAttributes(ctx context.Context, args []string, cmdCtx cmdCor
workflowAttr, err := cmdCtx.AdminFetcherExt().FetchWorkflowAttributes(ctx,
project, domain, workflowName, admin.MatchableResource_TASK_RESOURCE)
if err != nil {
taskResourceAttrFileConfig.DumpTaskResourceAttr(ctx, fileName)
return err
}
if workflowAttr.GetAttributes() == nil || workflowAttr.GetAttributes().GetMatchingAttributes() == nil {
return fmt.Errorf("attribute doesn't exist")
return fmt.Errorf("invalid matching attribute returned with nil data")
}
// Update the shadow config with the fetched taskResourceAttribute which can then be written to a file which can then be called for an update.
taskResourceAttrFileConfig.TaskResourceAttributes = workflowAttr.GetAttributes().GetMatchingAttributes().GetTaskResourceAttributes()
Expand All @@ -84,10 +86,11 @@ func getTaskResourceAttributes(ctx context.Context, args []string, cmdCtx cmdCor
projectDomainAttr, err := cmdCtx.AdminFetcherExt().FetchProjectDomainAttributes(ctx,
project, domain, admin.MatchableResource_TASK_RESOURCE)
if err != nil {
taskResourceAttrFileConfig.DumpTaskResourceAttr(ctx, fileName)
return err
}
if projectDomainAttr.GetAttributes() == nil || projectDomainAttr.GetAttributes().GetMatchingAttributes() == nil {
return fmt.Errorf("attribute doesn't exist")
return fmt.Errorf("invalid matching attribute returned with nil data")
}
// Update the shadow config with the fetched taskResourceAttribute which can then be written to a file which can then be called for an update.
taskResourceAttrFileConfig.TaskResourceAttributes = projectDomainAttr.GetAttributes().GetMatchingAttributes().GetTaskResourceAttributes()
Expand Down
10 changes: 5 additions & 5 deletions flytectl/cmd/get/matchable_task_resource_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestGetTaskResourceAttributes(t *testing.T) {
assert.Nil(t, err)
u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes",
ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE)
tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`)
tearDownAndVerify(t, `{"Project":"dummyProject","Domain":"dummyDomain","Workflow":"","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`)
})
t.Run("successful get project domain attribute and write to file", func(t *testing.T) {
var args []string
Expand All @@ -82,7 +82,7 @@ func TestGetTaskResourceAttributes(t *testing.T) {
assert.Nil(t, err)
u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes",
ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE)
tearDownAndVerify(t, `wrote the config to file temp-output-file`)
tearDownAndVerify(t, `written the config to file temp-output-file`)
})
t.Run("successful get project domain attribute and write to file failure", func(t *testing.T) {
var args []string
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestGetTaskResourceAttributes(t *testing.T) {
assert.Equal(t, fmt.Errorf("failed to fetch response"), err)
u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes",
ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE)
tearDownAndVerify(t, ``)
tearDownAndVerify(t, `{"Project":"dummyProject","Domain":"dummyDomain","Workflow":""}`)
})
t.Run("successful get workflow attribute", func(t *testing.T) {
var args []string
Expand All @@ -124,7 +124,7 @@ func TestGetTaskResourceAttributes(t *testing.T) {
u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes",
ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow",
admin.MatchableResource_TASK_RESOURCE)
tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`)
tearDownAndVerify(t, `{"Project":"dummyProject","Domain":"dummyDomain","Workflow":"workflow","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`)
})
t.Run("failed get workflow attribute", func(t *testing.T) {
var args []string
Expand All @@ -139,6 +139,6 @@ func TestGetTaskResourceAttributes(t *testing.T) {
u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes",
ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow",
admin.MatchableResource_TASK_RESOURCE)
tearDownAndVerify(t, ``)
tearDownAndVerify(t, `{"Project":"dummyProject","Domain":"dummyDomain","Workflow":"workflow"}`)
})
}
12 changes: 12 additions & 0 deletions flytectl/cmd/get/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ Retrieves task by name within project and domain.
bin/flytectl task -p flytesnacks -d development core.basic.lp.greet
Retrieves latest version of task by name within project and domain.
::
flytectl get task -p flytesnacks -d development core.basic.lp.greet --latest
Retrieves particular version of task by name within project and domain.
::
flytectl get workflow -p flytesnacks -d development core.basic.lp.greet --version v2
Retrieves project by filters.
::
Expand Down
Loading

0 comments on commit 36c1e4f

Please sign in to comment.