From fd122e60cd5a15d576c237b02a610f5e37a5fa7c Mon Sep 17 00:00:00 2001 From: droctothorpe Date: Fri, 2 Aug 2024 09:59:00 -0400 Subject: [PATCH] Improve logic and update tests Signed-off-by: droctothorpe Co-authored-by: zazulam --- backend/src/v2/compiler/argocompiler/argo.go | 27 +++++++++++++------ .../create_mount_delete_dynamic_pvc.yaml | 12 ++++----- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/backend/src/v2/compiler/argocompiler/argo.go b/backend/src/v2/compiler/argocompiler/argo.go index cfa4477d0c78..f4c83d554fc3 100644 --- a/backend/src/v2/compiler/argocompiler/argo.go +++ b/backend/src/v2/compiler/argocompiler/argo.go @@ -278,14 +278,25 @@ func (c *workflowCompiler) extractFunctionName(componentName string) string { } executorLabel := c.spec.Components[componentName].GetExecutorLabel() log.Debug("executorLabel: ", executorLabel) - for executorName, executorValue := range c.executors { - log.Debug("executorName: ", executorName) - if executorName == executorLabel { - args := executorValue.GetContainer().Args - componentFunctionName := args[len(args)-1] - log.Debug("componentFunctionName: ", componentFunctionName) - - return componentFunctionName + // There are more nested conditionals here than we would prefer, but we + // don't want to make any assumptions about the presence of specific fields + // in the IR. + if c.executors != nil { + for executorName, executorValue := range c.executors { + log.Debug("executorName: ", executorName) + if executorName == executorLabel { + args := executorValue.GetContainer().GetArgs() + if args != nil { + if len(args) > 1 { + penultimateArg := args[len(args)-2] + if penultimateArg == "--function_to_execute" { + componentFunctionName := args[len(args)-1] + log.Debug("componentFunctionName: ", componentFunctionName) + return componentFunctionName + } + } + } + } } } diff --git a/backend/src/v2/compiler/argocompiler/testdata/create_mount_delete_dynamic_pvc.yaml b/backend/src/v2/compiler/argocompiler/testdata/create_mount_delete_dynamic_pvc.yaml index 45ba6039ee02..0ef25ba74c90 100644 --- a/backend/src/v2/compiler/argocompiler/testdata/create_mount_delete_dynamic_pvc.yaml +++ b/backend/src/v2/compiler/argocompiler/testdata/create_mount_delete_dynamic_pvc.yaml @@ -8,9 +8,9 @@ spec: parameters: - name: kubernetes-comp-comp value: '{"pvcMount":[{"mountPath":"/data","taskOutputParameter":{"outputParameterKey":"name","producerTask":"createpvc"}}]}' - - name: components-comp-comp + - name: components-comp value: '{"executorLabel":"exec-comp"}' - - name: implementations-comp-comp + - name: implementations-comp value: '{"args":["--executor_input","{{$}}","--function_to_execute","comp"],"command":["sh","-c","\nif ! [ -x \"$(command -v pip)\" ]; then\n python3 -m ensurepip || python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1 @@ -197,11 +197,11 @@ spec: - arguments: parameters: - name: component - value: '{{workflow.parameters.components-comp-comp}}' + value: '{{workflow.parameters.components-comp}}' - name: task value: '{"cachingOptions":{"enableCache":true},"componentRef":{"name":"comp-comp"},"dependentTasks":["createpvc"],"taskInfo":{"name":"comp"}}' - name: container - value: '{{workflow.parameters.implementations-comp-comp}}' + value: '{{workflow.parameters.implementations-comp}}' - name: parent-dag-id value: '{{inputs.parameters.parent-dag-id}}' - name: kubernetes-config @@ -222,11 +222,11 @@ spec: - arguments: parameters: - name: component - value: '{{workflow.parameters.components-comp-comp}}' + value: '{{workflow.parameters.components-comp}}' - name: task value: '{"cachingOptions":{"enableCache":true},"componentRef":{"name":"comp-comp-2"},"dependentTasks":["comp","createpvc"],"taskInfo":{"name":"comp-2"}}' - name: container - value: '{{workflow.parameters.implementations-comp-comp}}' + value: '{{workflow.parameters.implementations-comp}}' - name: parent-dag-id value: '{{inputs.parameters.parent-dag-id}}' - name: kubernetes-config