-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 for Resource creation where template has same parameter templating #1283
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a63eac7
Fix for Resource creation where template has same parameter templating
sarabala1979 b8f78a1
Merge remote-tracking branch 'origin/master' into Issue1239
sarabala1979 e9b8f4a
added test
sarabala1979 7be7831
fixed gofmt issue
sarabala1979 89428c5
fixed format
sarabala1979 cd7e89b
fixed gofmt on common.go
sarabala1979 da91685
fixed testcase
sarabala1979 87416e2
fixed gofmt
sarabala1979 4987093
Added unit testcase and documented
sarabala1979 c1a96ca
fixed Gofmt format
sarabala1979 346193a
updated comments
sarabala1979 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This template demonstrates the customer variable suppport. | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: custom-template-variable- | ||
spec: | ||
entrypoint: hello-hello-hello | ||
|
||
templates: | ||
- name: hello-hello-hello | ||
steps: | ||
- - name: hello1 | ||
template: whalesay | ||
arguments: | ||
parameters: [{name: message, value: "hello1"}] | ||
- - name: hello2a | ||
template: whalesay | ||
arguments: | ||
parameters: [{name: message, value: "hello2a"}] | ||
- name: hello2b | ||
template: whalesay | ||
arguments: | ||
parameters: [{name: message, value: "hello2b"}] | ||
|
||
- name: whalesay | ||
inputs: | ||
parameters: | ||
- name: message | ||
container: | ||
image: docker/whalesay | ||
command: [cowsay] | ||
args: ["{{custom.variable}}"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,11 @@ func resolveAllVariables(scope map[string]interface{}, tmplStr string) error { | |
fstTmpl := fasttemplate.New(tmplStr, "{{", "}}") | ||
|
||
fstTmpl.ExecuteFuncString(func(w io.Writer, tag string) (int, error) { | ||
|
||
// Skip the custom variable references | ||
if !checkValidWorkflowVariablePrefix(tag) { | ||
return 0, nil | ||
} | ||
_, ok := scope[tag] | ||
if !ok && unresolvedErr == nil { | ||
if (tag == "item" || strings.HasPrefix(tag, "item.")) && allowAllItemRefs { | ||
|
@@ -245,6 +250,16 @@ func resolveAllVariables(scope map[string]interface{}, tmplStr string) error { | |
return unresolvedErr | ||
} | ||
|
||
// checkValidWorkflowVariablePrefix is a helper methood check variable starts workflow root elements | ||
func checkValidWorkflowVariablePrefix(tag string) bool { | ||
for _, rootTag := range common.GlobalVarValidWorkflowVariablePrefix { | ||
if strings.HasPrefix(tag, rootTag) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch. Thanks. I will fix it |
||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func validateNonLeaf(tmpl *wfv1.Template) error { | ||
if tmpl.ActiveDeadlineSeconds != nil { | ||
return errors.Errorf(errors.CodeBadRequest, "templates.%s.activeDeadlineSeconds is only valid for leaf templates", tmpl.Name) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
sure