Skip to content

Commit

Permalink
fix: Avoid overriding the Workflow parameter when it is merging with …
Browse files Browse the repository at this point in the history
…WorkflowTemplate parameter (#3651)
  • Loading branch information
sarabala1979 committed Jul 31, 2020
1 parent 89e05bd commit 819bfdb
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2798,7 +2798,7 @@ func (woc *wfOperationCtx) loadExecutionSpec() (wfv1.TemplateReferenceHolder, wf
}

// Merge the workflow spec and storedWorkflowspec.
targetWf := wfv1.Workflow{Spec: woc.wf.Spec}
targetWf := wfv1.Workflow{Spec: *woc.wf.Spec.DeepCopy()}
err := wfutil.MergeTo(&wfv1.Workflow{Spec: *woc.wf.Status.StoredWorkflowSpec}, &targetWf)
if err != nil {
return nil, executionParameters, err
Expand Down
83 changes: 83 additions & 0 deletions workflow/controller/operator_workflow_template_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,86 @@ func TestWorkflowTemplateRefInvalidWF(t *testing.T) {
assert.Equal(t, wfv1.NodeError, woc.wf.Status.Phase)
})
}

var wftWithParam = `
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: params-test-1
namespace: default
spec:
entrypoint: main
arguments:
parameters:
- name: a-a
value: "10"
- name: b
value: ""
- name: c-c
value: "0"
- name: d
value: ""
- name: e-e
value: "10"
- name: f
value: ""
- name: g-g
value: "1"
- name: h
value: ""
- name: i-i
value: "{}"
- name: things
value: "[]"
templates:
- name: main
steps:
- - name: echoitems
template: echo
- name: echo
container:
image: busybox
command: [echo]
args: ["{{workflows.parameters.a-a}} = {{workflows.parameters.g-g}}"]
`
var wfWithParam = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: params-test-1-grx2n
namespace: default
spec:
arguments:
parameters:
- name: f
value: f
- name: g-g
value: 2
- name: h
value: h
- name: i-i
value: '{}'
- name: things
value: '[{"a":"1","nested":{"B":"3"}},{"a":"2"}]'
- name: a-a
value: 5
workflowTemplateRef:
name: params-test-1
`

func TestWorkflowTemplateRefParamMerge(t *testing.T) {
wf := unmarshalWF(wfWithParam)
wftmpl := unmarshalWFTmpl(wftWithParam)

t.Run("CheckArgumentFromWF", func(t *testing.T) {
cancel, controller := newController(wf, wftmpl)
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
_, _, err := woc.loadExecutionSpec()
assert.NoError(t, err)
assert.Equal(t, wf.Spec.Arguments.Parameters, woc.wf.Spec.Arguments.Parameters)
})

}

0 comments on commit 819bfdb

Please sign in to comment.