From 4da8fd94004d535bc79b2cbfa77f6c8683d0c547 Mon Sep 17 00:00:00 2001 From: Saravanan Balasubramanian <33908564+sarabala1979@users.noreply.github.com> Date: Fri, 23 Jul 2021 15:39:42 -0700 Subject: [PATCH] fix(controller): Global parameter is not getting updated (#6401) * fix(controller): Global parameter is not getting updated Signed-off-by: Saravanan Balasubramanian --- workflow/controller/operator.go | 8 +++++++- workflow/controller/operator_test.go | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go index 31565f360650..659d17c91da9 100644 --- a/workflow/controller/operator.go +++ b/workflow/controller/operator.go @@ -3378,7 +3378,13 @@ func (woc *wfOperationCtx) mergedTemplateDefaultsInto(originalTmpl *wfv1.Templat } func (woc *wfOperationCtx) substituteGlobalVariables() error { - wfSpec, err := json.Marshal(woc.execWf.Spec) + execWfSpec := woc.execWf.Spec + + // To Avoid the stale Global parameter value substitution to templates. + // Updated Global parameter values will be substituted in 'executetemplate' for templates. + execWfSpec.Templates = nil + + wfSpec, err := json.Marshal(execWfSpec) if err != nil { return err } diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index 43010e234402..ea959853f1af 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -6894,6 +6894,9 @@ func TestSubstituteGlobalVariables(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, woc.execWf) assert.Equal(t, "mutex1", woc.execWf.Spec.Synchronization.Mutex.Name) + tempStr, err := json.Marshal(woc.execWf.Spec.Templates) + assert.NoError(t, err) + assert.Contains(t, string(tempStr), "{{workflow.parameters.message}}") } var wfPending = `