From cf4edcea8de5d38b559a3cd392c1c649677a34a0 Mon Sep 17 00:00:00 2001 From: Dennis Keck <26092524+fellhorn@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:30:25 +0200 Subject: [PATCH] Handle inputs in subworkflows Signed-off-by: Dennis Keck <26092524+fellhorn@users.noreply.github.com> --- flytectl/cmd/compile/compile.go | 73 +++++++++++++++--- .../cmd/compile/testdata/launchplan-in-wf.tgz | Bin 777 -> 875 bytes 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/flytectl/cmd/compile/compile.go b/flytectl/cmd/compile/compile.go index f64991f941b..16d1fcf9a72 100644 --- a/flytectl/cmd/compile/compile.go +++ b/flytectl/cmd/compile/compile.go @@ -81,24 +81,15 @@ func compileFromPackage(packagePath string) error { } var providers []common.InterfaceProvider - for _, plan := range plans { - providers = append(providers, compiler.NewLaunchPlanInterfaceProvider(*plan)) - } + var compiledWorkflows = map[string]*core.CompiledWorkflowClosure{} // compile workflows - for wfName, workflow := range workflows { - - fmt.Println("\nCompiling workflow:", wfName) + for _, workflow := range workflows { + providers, err = handleWorkflow(workflow, compiledTasks, compiledWorkflows, providers, plans, workflows) - _, err := compiler.CompileWorkflow(workflow.Template, - workflow.SubWorkflows, - compiledTasks, - providers) if err != nil { - fmt.Println(":( Error Compiling workflow:", wfName) return err } - } fmt.Println("All Workflows compiled successfully!") @@ -109,6 +100,64 @@ func compileFromPackage(packagePath string) error { return nil } +func handleWorkflow( + workflow *admin.WorkflowSpec, + compiledTasks []*core.CompiledTask, + compiledWorkflows map[string]*core.CompiledWorkflowClosure, + compiledLaunchPlanProviders []common.InterfaceProvider, + plans map[string]*admin.LaunchPlan, + workflows map[string]*admin.WorkflowSpec) ([]common.InterfaceProvider, error) { + reqs, _ := compiler.GetRequirements(workflow.Template, workflow.SubWorkflows) + wfName := workflow.Template.Id.Name + + // Check if all the subworkflows referenced by launchplan are compiled + for _, lpId := range reqs.GetRequiredLaunchPlanIds() { + lpWfName := plans[lpId.Name].Spec.WorkflowId.Name + missingWorkflow := workflows[lpWfName] + if compiledWorkflows[lpWfName] == nil { + // Recursively compile the missing workflow first + err := error(nil) + compiledLaunchPlanProviders, err = handleWorkflow(missingWorkflow, compiledTasks, compiledWorkflows, compiledLaunchPlanProviders, plans, workflows) + if err != nil { + return nil, err + } + } + } + + fmt.Println("\nCompiling workflow:", wfName) + + wf, err := compiler.CompileWorkflow(workflow.Template, + workflow.SubWorkflows, + compiledTasks, + compiledLaunchPlanProviders) + + if err != nil { + fmt.Println(":( Error Compiling workflow:", wfName) + return nil, err + } + compiledWorkflows[wfName] = wf + + // Update the expected inputs and outputs for the launchplans which reference this workflow + for _, plan := range plans { + if plan.Spec.WorkflowId.Name == wfName { + plan.Closure.ExpectedOutputs = wf.Primary.Template.Interface.Outputs + newMap := make(map[string]*core.Parameter) + + for key, value := range wf.Primary.Template.Interface.Inputs.Variables { + newMap[key] = &core.Parameter{ + Var: value, + } + } + plan.Closure.ExpectedInputs = &core.ParameterMap{ + Parameters: newMap, + } + compiledLaunchPlanProviders = append(compiledLaunchPlanProviders, compiler.NewLaunchPlanInterfaceProvider(*plan)) + } + } + + return compiledLaunchPlanProviders, nil +} + const ( compileShort = `Validate flyte packages without registration needed.` compileLong = ` diff --git a/flytectl/cmd/compile/testdata/launchplan-in-wf.tgz b/flytectl/cmd/compile/testdata/launchplan-in-wf.tgz index 1a78ceaf22acedd4f12d0dccec9e08b50cbb3aa4..b297277ce0b807eb705c203a0fcd6039e6072e4d 100644 GIT binary patch literal 875 zcmV-x1C;z9iwFq$#%5*$|7L7?bY(4YVPk7yXJsyQXLxo6{H z=8ny4ICHO|NA&39nbZHwof;3&qoBmxbyO5hyJ-*mnW8d=4*Mttx}DGo#O2ZRM70iE zq1)o`n8n^IjF~#4n#xSm!U*{P(e0ieH0n*i*P*>S^}8Vt#$C2b+g~4M{hOvfJTl8r zlE(;DH4)QIjTyS8Sxl^di&+*rRMK4kHST$C=kB=s#-AwoX9geSv!%T`Ujqq|0!Gpn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