Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid overriding the Workflow parameter when it is merging with WorkflowTemplate parameter #3651

Merged
merged 6 commits into from
Jul 31, 2020
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Expand Up @@ -2925,7 +2925,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()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ek!

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
Expand Up @@ -161,3 +161,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)
})

}