From 1355f8039ede0142c2c6a301f2a71f4a04d5c524 Mon Sep 17 00:00:00 2001 From: rushtehrani Date: Mon, 11 Jan 2021 20:05:58 -0800 Subject: [PATCH 1/2] only remove whitespaces in var references --- pkg/workflow_execution.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/workflow_execution.go b/pkg/workflow_execution.go index e3c05fe2..ad7fcc37 100644 --- a/pkg/workflow_execution.go +++ b/pkg/workflow_execution.go @@ -23,6 +23,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/watch" "net/http" + "regexp" yaml2 "sigs.k8s.io/yaml" "strconv" "strings" @@ -463,11 +464,12 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateID uint64, wor for i := range wf.Spec.Arguments.Parameters { param := wf.Spec.Arguments.Parameters[i] if param.Value != nil { - // Strip out whitespace from parameter value - formattedValue := strings.ReplaceAll(*param.Value, " ", "") - param.Value = &formattedValue - *param.Value = strings.ReplaceAll(*param.Value, "{{workflow.namespace}}", namespace) - *param.Value = strings.ReplaceAll(*param.Value, "{{workspace.namespace}}", namespace) + re, reErr := regexp.Compile(`{{\s*workflow.namespace\s*}}|{{\s*workspace.namespace\s*}}`) + if reErr != nil { + return nil, reErr + } + *param.Value = re.ReplaceAllString(*param.Value, namespace) + *param.Value = re.ReplaceAllString(*param.Value, namespace) } newParameters = append(newParameters, param) From 1d0c898fa43cc3315ec8f380321f51f903ddaee7 Mon Sep 17 00:00:00 2001 From: rushtehrani Date: Mon, 11 Jan 2021 20:37:23 -0800 Subject: [PATCH 2/2] code cleanup + no param mutation --- pkg/workflow_execution.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/workflow_execution.go b/pkg/workflow_execution.go index ad7fcc37..9a712a56 100644 --- a/pkg/workflow_execution.go +++ b/pkg/workflow_execution.go @@ -468,8 +468,8 @@ func (c *Client) createWorkflow(namespace string, workflowTemplateID uint64, wor if reErr != nil { return nil, reErr } - *param.Value = re.ReplaceAllString(*param.Value, namespace) - *param.Value = re.ReplaceAllString(*param.Value, namespace) + value := re.ReplaceAllString(*param.Value, namespace) + param.Value = &value } newParameters = append(newParameters, param)