-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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(controller): allow to use global params with withParam #2757
fix(controller): allow to use global params with withParam #2757
Conversation
workflow/controller/dag.go
Outdated
@@ -526,7 +526,12 @@ func (woc *wfOperationCtx) resolveDependencyReferences(dagCtx *dagContext, task | |||
return nil, errors.InternalWrapError(err) | |||
} | |||
fstTmpl := fasttemplate.New(string(taskBytes), "{{", "}}") | |||
newTaskStr, err := common.Replace(fstTmpl, scope.replaceMap(), true) | |||
|
|||
replaceMap := scope.replaceMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like
replaceMap := scope.replaceMap() | |
replaceMap := scope.replaceMap(woc.globalParams) |
Would be cleaner.
You could edit the replaceMap
function to include this optional parameter and add its contents to the scope if it's not nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the method name replaceMap
is not intuitive to accept an argument of params extension. Maybe, we can have something like mergeParams
utility method in the common package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to introduce mergeParams
utility method, we should make another PR to replace other codes meging params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could change the name to something like prepareScope
, here is an example where I do something similar:
This is minor though, I'll leave it up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I found there're many cases of merging params, I defined Params
type which has Clone
and Merge
functions so we can replace those codes with one line.
I also found the order of merging was not correct in my original commit of this PR. scoep.replaceMap()
should be merged into globalParmas
but not the opposite.
…resolution-with-with-param
workflow/controller/dag.go
Outdated
@@ -526,7 +526,12 @@ func (woc *wfOperationCtx) resolveDependencyReferences(dagCtx *dagContext, task | |||
return nil, errors.InternalWrapError(err) | |||
} | |||
fstTmpl := fasttemplate.New(string(taskBytes), "{{", "}}") | |||
newTaskStr, err := common.Replace(fstTmpl, scope.replaceMap(), true) | |||
|
|||
replaceMap := scope.replaceMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could change the name to something like prepareScope
, here is an example where I do something similar:
This is minor though, I'll leave it up to you.
@simster7 Could you review it again? |
util/params/params.go
Outdated
@@ -0,0 +1,21 @@ | |||
package params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Workflow specific util, so it shouldn't be at the top-level util folder. Can you add this to the workflow/common
package? You can add a new file there, but it should still be under the common
package.
util/params/params.go
Outdated
@@ -0,0 +1,21 @@ | |||
package params | |||
|
|||
type Params map[string]string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type Params map[string]string | |
type Parameters map[string]string |
Full name is more clear.
workflow/common/util.go
Outdated
@@ -300,19 +301,13 @@ func ProcessArgs(tmpl *wfv1.Template, args wfv1.ArgumentsProvider, globalParams, | |||
} | |||
|
|||
// SubstituteParams returns a new copy of the template with global, pod, and input parameters substituted | |||
func SubstituteParams(tmpl *wfv1.Template, globalParams, localParams map[string]string) (*wfv1.Template, error) { | |||
func SubstituteParams(tmpl *wfv1.Template, globalParams, localParams params.Params) (*wfv1.Template, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we move the util file under common
, we won't need the import prefix anymore.
util/params/params_test.go
Outdated
params := Params{"foo": "1"} | ||
newParams := params.Clone() | ||
assert.Equal(t, params, newParams) | ||
assert.NotSame(t, ¶ms, &newParams) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this is important.
util/params/params.go
Outdated
return newParams | ||
} | ||
|
||
func (ps Params) Clone() Params { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeepCopy
is the name we use for this in Argo.
workflow/controller/scope.go
Outdated
@@ -14,7 +15,7 @@ type wfScope struct { | |||
} | |||
|
|||
// replaceMap returns a replacement map of strings intended to be used simple string substitution | |||
func (s *wfScope) replaceMap() map[string]string { | |||
func (s *wfScope) replaceMap() params.Params { | |||
replaceMap := make(map[string]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be?
replaceMap := make(map[string]string) | |
replaceMap := make(params.Params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more minor comments
workflow/controller/scope.go
Outdated
@@ -14,8 +15,8 @@ type wfScope struct { | |||
} | |||
|
|||
// replaceMap returns a replacement map of strings intended to be used simple string substitution | |||
func (s *wfScope) replaceMap() map[string]string { | |||
replaceMap := make(map[string]string) | |||
func (s *wfScope) replaceMap() common.Parameters { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this function parameters()
or getParameters()
or something similar
workflow/controller/workflowpod.go
Outdated
podParams[k] = v | ||
} | ||
func substitutePodParams(pod *apiv1.Pod, globalParams common.Parameters, tmpl *wfv1.Template) (*apiv1.Pod, error) { | ||
podParams := globalParams.Merge() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be DeepCopy
if Merge
has not arguments?
podParams := globalParams.Merge() | |
podParams := globalParams.DeepCopy() |
@simster7 Fixed. Please check it again! |
Kudos, SonarCloud Quality Gate passed!
|
Back-ported to 2.7 |
Checklist:
(b)
"fix(controller): Updates such and such. Fixes #1234"
.