Skip to content
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

Allow brackets inside Tekton expressions #376

Merged
merged 1 commit into from
Jan 23, 2020

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented Jan 22, 2020

We were previously using a regex to extract expressions within
TriggerBindings. The regex only extracted between the initial $(
and the first occurrence of the ). This meant that some valid
JSONPath expressions that contained brackets (e.g. filters) were
incorrectly extracted.

This commit fixes the issue by splitting the string on $( and then
extracting until the first unbalanced occurrence of ).

Fixes #365

Changes

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

TriggerBinding values now correctly detect embedded brackets

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 22, 2020
@dibyom
Copy link
Member Author

dibyom commented Jan 22, 2020

/hold

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 22, 2020
@dibyom
Copy link
Member Author

dibyom commented Jan 23, 2020

❌ CLAs are signed, but unable to verify author consent

Manually verified with @afrittoli that he does indeed consent to Co-Authorship 😝

@dibyom dibyom added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 23, 2020
@dibyom
Copy link
Member Author

dibyom commented Jan 23, 2020

/cla yes

@dibyom
Copy link
Member Author

dibyom commented Jan 23, 2020

Looks like I can't manually update the cla label anymore 😞

@afrittoli you might have to comment @googlebot I consent

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 23, 2020
@afrittoli
Copy link
Member

@googlebot I consent

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@afrittoli
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 23, 2020
Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good! Just want to add a few tests just to cover some potential edge cases.

pkg/template/jsonpath_test.go Show resolved Hide resolved
pkg/template/jsonpath.go Show resolved Hide resolved
return results
}
// Splits string on $( to find potential Tekton expressions
maybeExpressions := strings.Split(in, "$(")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we want to handle expressions like $($())? Let's also add a test to verify the behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, so this is the interesting one 😄

currently, we'd return $() i.e. the inner expression

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ is usually the root element in JSONPath though in the kubectl jsonpath template syntax that we are using does not mention $ at all

https://goessner.net/articles/JsonPath/

https://kubernetes.io/docs/reference/kubectl/jsonpath/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubectl get pod -o=jsonpath='{$(.items[0])}'

error: error parsing jsonpath {$(.items[0])}, unrecognized character in action: U+0028 '('

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, IMO we can document that if you have embed $()...we'll just use the innermost one e.g. "$($($(blahblah)))" will return $(blahblah)

what do you think @wlynch @afrittoli ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the innermost rule applies and we get $(foo)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a error is definitely an option though documented/defined behavior for nested $( is also an option. Don't feel too strongly about either

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the -bar bit feels unexpected to me. I'm leaning towards making it an error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bar is only ignored as part of the jsonpath expression...when we do the repalcements -> it still shows up as part of the string i,e, if $(foo) evals to "abc" the value of the binding is $($(abc)-bar)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Okay, documenting that as a first step sounds good to me then! We can always revisit this later.

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 23, 2020
We were previously using a regex to extract expressions within
TriggerBindings. The regex only extracted between the initial `$(`
and the first occurrence of the `)`. This meant that some valid
JSONPath expressions that contained brackets (e.g. filters) were
incorrectly extracted.

This commit fixes the issue by splitting the string on `$(` and then
extracting until the first "unbalanced" occurrence of `)`.

Fixes tektoncd#365

Co-Authored-By: Andrea Frittoli <[email protected]>
Signed-off-by: Dibyo Mukherjee <[email protected]>
@wlynch
Copy link
Member

wlynch commented Jan 23, 2020

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 23, 2020
@wlynch
Copy link
Member

wlynch commented Jan 23, 2020

/approve

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wlynch

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 23, 2020
@tekton-robot tekton-robot merged commit 304ef62 into tektoncd:master Jan 23, 2020
@dibyom dibyom deleted the issues/365 branch January 23, 2020 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSONPath filter expression is invalid
5 participants