-
Notifications
You must be signed in to change notification settings - Fork 420
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
Modify spec params to avoid confusion between resourcetemplates and triggertemplate params #589
Conversation
The following is the coverage report on the affected files.
|
Thanks for opening this @savitaashture I won't get to this today but will put in on my list for tomorrow! |
Might be worth rewording as - The |
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.
Thanks @savitaashture .Code looks fine to me. I'll try this out on my env. Given that this is a pretty far reaching API change, let's discuss it once in next week's WG before merging?
func (tt *TriggerTemplate) SetDefaults(ctx context.Context) {} | ||
func (tt *TriggerTemplate) SetDefaults(ctx context.Context) { | ||
// This is a temporary logic to have a backward compatibility with the original params. | ||
// TODO(savitaashture): remove below logic once after the complete deprecation of Spec.DeprecatedParams |
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 should open an issue to remove this and link to that issue here instead!
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 i will open and update in the code comments
Yes +1 to discuss before merging
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.
Created issue to track the removal of deprecated tag params
if _, ok := declaredParamNames[templateParamName]; !ok { | ||
// This logic is to get the tag and display in error dynamically for both ttparams and params. | ||
// TODO(savitaashture): remove params once after the complete deprecation of spec.DeprecatedParams | ||
var tag 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.
Question: Until we start using only $(ttparams) for replacement, we cannot support #525 right?
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.
Yes because till that time we will have validation for params
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dibyom The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
470b7f8
to
8c99a0a
Compare
The following is the coverage report on the affected files.
|
Drive by comment - instead of changing the name of the params field, you could change how the replacement works, e.g. use whaddaya think (ignore me if this has been discussed already) |
Hi @bobcatfish Its good point |
Just consistency! Across tekton we have multiple Mostly a subjective opinion tho! |
I like the How do you feel about keeping the |
@dibyom yes i think we need to keep Let me understand clearly one of your point here
If thats the thing i feel it creates bit confusion 🤔 OR This way
|
Yeah, the first one. I agree it can be a bit confusing 😄 On the other hand calling the field |
Ya even i am thinking of confusing part. |
8c99a0a
to
2bbdf49
Compare
@dibyom Modified as per the discussion Changes: |
/retest |
pkg/template/resource.go
Outdated
@@ -111,7 +111,7 @@ func ApplyParamsToResourceTemplate(params []triggersv1.Param, rt json.RawMessage | |||
// param value substituted for all matching param variables in the template | |||
func applyParamToResourceTemplate(param triggersv1.Param, rt json.RawMessage) json.RawMessage { | |||
// Assume the param is valid | |||
paramVariable := fmt.Sprintf("$(params.%s)", param.Name) | |||
paramVariable := fmt.Sprintf("$(tt.params.%s)", param.Name) |
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.
Are we just supporting $(tt.params)
for now. Shouldn't we support both $(params)
or $(tt.params)
for a release or two?
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.
Updated changes
Please do have a look
Thank you
2bbdf49
to
52b1dbb
Compare
The following is the coverage report on the affected files.
|
52b1dbb
to
ff20c85
Compare
The following is the coverage report on the affected files.
|
pkg/template/resource.go
Outdated
// Assume the param is valid | ||
paramVariable := fmt.Sprintf("$(params.%s)", param.Name) | ||
if len(templateParams) == 0 { | ||
paramVariable = fmt.Sprintf("$(tt.params.%s)", param.Name) |
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.
Is there a reason we cannot attempt to replace with both $(params)
as well as $(tt.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.
The reason is we will not be getting the information on user provided ResourceTemplate params whether its $(params)
or $(tt.params)
So currently with the help of regular expression able to distinguish whether its
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 don't think this works if a user mixes both params and tt.params in the same file. It should be safe to do a double pass - e.g.
for _, tag := range []string{ "params", "tt.params"} {
paramVariable := fmt.Sprintf("$(%s.%s)", tag, param.Name)
rt = bytes.Replace(rt, []byte(paramVariable), []byte(paramValue), -1)
}
- name: url | ||
value: $(params.gitrepositoryurl) | ||
value: $(tt.params.gitrepositoryurl) | ||
``` | ||
|
||
`TriggerTemplates` currently support the following [Tekton Pipelines](https://github.com/tektoncd/pipelines) resources: |
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.
Updated doc 👍
Thank you
ff20c85
to
6120b05
Compare
The following is the coverage report on the affected files.
|
/test pull-tekton-triggers-integration-tests |
1 similar comment
/test pull-tekton-triggers-integration-tests |
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.
Almost there! No particular preference on tt.params (only alternative I can think of is template.params
, but I don't care that much).
Few minor comments, otherwise SGTM
templateParams := paramsRegexp.FindAllSubmatch(template.RawExtension.Raw, -1) | ||
for _, templateParam := range templateParams { | ||
templateParamName := string(templateParam[1]) | ||
templateParamName := string(templateParam[2]) |
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 realize this is following what was set before, but the direct array access is at risk for nil panics. I think we should do 2 things:
- Have a length check prior to accessing
templateParam[2]
. - Create a more exhaustive set of regexp checks instead of the more e2e tests we see here. (mainly to give us more confidence that the regexp is matching to what we expect, even in unexpected cases).
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.
Actually
templateParams := paramsRegexp.FindAllSubmatch(template.RawExtension.Raw, -1)
templateParams length will be 0 in any unexpected cases because of Regular Expression
regexp.MustCompile(`\$\((params|tt.params).([_a-zA-Z][_a-zA-Z0-9.-]*)\)`)
If user provides any such values like below
1. params1.foo
2. tt1.params.foo
3. tt.params1.foo
4. tt.foo
5. .foo
the templateParams
itself is 0
and because of that it never enters into for loop
But yes need to add more test cases to ensures the regex will not break.
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.
Added test cases to cover few more scenario
@@ -153,18 +153,18 @@ func TestHandleEvent(t *testing.T) { | |||
Kind: "PipelineResource", | |||
}, | |||
ObjectMeta: metav1.ObjectMeta{ | |||
Name: "$(params.name)", | |||
Name: "$(tt.params.name)", |
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 should probably leave some of these tests using the old params syntax to ensure backwards compatibility, since this is the first place where we are actually using the value outside of validation.
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.
+1 to having some tests with the old $(params)
pkg/template/resource.go
Outdated
// Assume the param is valid | ||
paramVariable := fmt.Sprintf("$(params.%s)", param.Name) | ||
if len(templateParams) == 0 { | ||
paramVariable = fmt.Sprintf("$(tt.params.%s)", param.Name) |
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 don't think this works if a user mixes both params and tt.params in the same file. It should be safe to do a double pass - e.g.
for _, tag := range []string{ "params", "tt.params"} {
paramVariable := fmt.Sprintf("$(%s.%s)", tag, param.Name)
rt = bytes.Replace(rt, []byte(paramVariable), []byte(paramValue), -1)
}
6120b05
to
c648333
Compare
The following is the coverage report on the affected files.
|
…riggertemplate params
c648333
to
2e7a780
Compare
The following is the coverage report on the affected files.
|
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.
/lgtm
Changes
PR helps to avoid confusion from
TriggerTemplate params
toresourceTemplate params
by keeping params of spec as it is and using $(tt.params.) for the substitution.
So, this way we no need to handle the backward compatibility as per the discussion over the comments
Fixes #508
Tried to do tag configurable, given the way ObjectDefaulter and SetDefaults work, neither could accomplish the switch properly. ObjectDefaulter could have done it, but the way the tests are configured do not cause the Defaults to be executed since the objects aren't actually decoded.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Release Notes
The substitution for
params
modified from$(params.gitrevision)
to$(tt.params.gitrevision)
.And the the examples
For a release or two $(params) supported and later it will be deprecated.
Created issue to track the same
cc @dibyom