Skip to content

Commit

Permalink
fix(controller): Revert prepending ExecutorScriptSourcePath which bro…
Browse files Browse the repository at this point in the history
…ught a breaking change in args handling (#4884)

This reverts commit 64ae330.

Signed-off-by: Arthur Outhenin-Chalandre <arthur@cri.epita.fr>
  • Loading branch information
MrFreezeex committed Feb 2, 2021
1 parent b68d63e commit 44a4f7e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
13 changes: 2 additions & 11 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,16 +2345,6 @@ func getStepOrDAGTaskName(nodeName string) string {
return nodeName
}

func extractMainCtrFromScriptTemplate(tmpl *wfv1.Template) apiv1.Container {
mainCtr := tmpl.Script.Container
// If script source is provided then pass all container args to the
// script instead of passing them to the container command directly
if tmpl.Script.Source != "" {
mainCtr.Args = append([]string{common.ExecutorScriptSourcePath}, mainCtr.Args...)
}
return mainCtr
}

func (woc *wfOperationCtx) executeScript(ctx context.Context, nodeName string, templateScope string, tmpl *wfv1.Template, orgTmpl wfv1.TemplateReferenceHolder, opts *executeTemplateOpts) (*wfv1.NodeStatus, error) {
node := woc.wf.GetNodeByName(nodeName)
if node == nil {
Expand All @@ -2370,7 +2360,8 @@ func (woc *wfOperationCtx) executeScript(ctx context.Context, nodeName string, t
return node, err
}

mainCtr := extractMainCtrFromScriptTemplate(tmpl)
mainCtr := tmpl.Script.Container
mainCtr.Args = append(mainCtr.Args, common.ExecutorScriptSourcePath)
_, err = woc.createWorkflowPod(ctx, nodeName, mainCtr, tmpl, &createWorkflowPodOpts{
includeScriptOutput: includeScriptOutput,
onExitPod: opts.onExitTemplate,
Expand Down
36 changes: 0 additions & 36 deletions workflow/controller/workflowpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,42 +69,6 @@ func TestScriptTemplateWithVolume(t *testing.T) {
assert.NoError(t, err)
}

var scriptTemplateWithArgsAndWithSource = `
name: script-with-args-and-with-source
script:
image: alpine:latest
command: [sh]
args: ["hello world"]
source: |
echo $@
`

// TestScriptTemplateMainCtrArgsWhenArgsAndWhenSource ensure order of merged args
// and script path is correct when both args and script source are specified
func TestScriptTemplateMainCtrArgsWhenArgsAndWhenSource(t *testing.T) {
tmpl := unmarshalTemplate(scriptTemplateWithArgsAndWithSource)
mainCtr := extractMainCtrFromScriptTemplate(tmpl)
assert.Equal(t, []string{"sh"}, mainCtr.Command)
assert.Equal(t, []string{common.ExecutorScriptSourcePath, "hello world"}, mainCtr.Args)
}

var scriptTemplateWithArgsAndWithoutSource = `
name: script-with-args-and-without-source
script:
image: alpine:latest
command: [echo]
args: ["hello world"]
`

// TestScriptTemplateMainCtrArgsWhenArgsAndWhenNoSource ensure only args are passed
// to the resulting container when script source is empty
func TestScriptTemplateMainCtrArgsWhenArgsAndWhenNoSource(t *testing.T) {
tmpl := unmarshalTemplate(scriptTemplateWithArgsAndWithoutSource)
mainCtr := extractMainCtrFromScriptTemplate(tmpl)
assert.Equal(t, []string{"echo"}, mainCtr.Command)
assert.Equal(t, []string{"hello world"}, mainCtr.Args)
}

var scriptTemplateWithOptionalInputArtifactProvided = `
name: script-with-input-artifact
inputs:
Expand Down

0 comments on commit 44a4f7e

Please sign in to comment.