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

fix: enable when expressions to use expr; add new json variables to avoid expr conflicts #9761

Merged
merged 11 commits into from
Oct 11, 2022

Conversation

juliev0
Copy link
Contributor

@juliev0 juliev0 commented Oct 6, 2022

Fixes #8911
Fixes #9742

This removes the validation check which prevents expr from being used in a "when" condition, which had gotten added here.

Apparently, the actual problem that was being addressed there was the fact that "workflow.parameters" couldn't be used in an expr expression. The issue was that there were conflicts since both "workflow.parameters" and "workflow.parameters.x" were variables that need replacing, and the call to evaluate expr can't handle cases in which one variable is a prefix of another. Therefore, this adds a new variable "workflow.parameters.json" which is equivalent to "workflow.parameters". "workflow.parameters" should eventually be phased out in favor of this. (For now, we can keep it: it's just that it can't be handled in an expr expression.)

container:
image: docker/whalesay:latest
image: argoproj/argosay:v1
command: [sh, -c]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

had to change the whalesay image to argosay image since apparently whalesay isn't supposed to be used for e2e tests

inputs:
parameters:
- name: should-print
- name: shouldPrint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the dash from the name since expr expressions which include dash need to be formatted with brackets due to the special character

Copy link
Member

Choose a reason for hiding this comment

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

Could you clarify with some examples? Does this mean names with dashes will not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I changed it back to the dashed name to show how you can handle that with expr.

BTW, this is the example Bala had, which I imitated.

Signed-off-by: Julie Vogelman <[email protected]>
Signed-off-by: Julie Vogelman <[email protected]>
@juliev0 juliev0 marked this pull request as ready for review October 6, 2022 22:07
@juliev0
Copy link
Contributor Author

juliev0 commented Oct 6, 2022

Assigned to @sarabala1979 since he and I discussed this one

@sarabala1979
Copy link
Member

@juliev0 PR LGTM. Can we add validation? so it will fail in validation

@juliev0
Copy link
Contributor Author

juliev0 commented Oct 8, 2022

@juliev0 PR LGTM. Can we add validation? so it will fail in validation

It's a good idea but I think it's a bigger ask than just this as we're not currently doing validation even in the case that somebody adds an expr which uses "workflow.blah" for example, let alone that they use "workflow.parameters". According to this line, "we do not validate expression templates". I'd be happy to add a separate issue and take it on if you like.

What I did realize was that I hadn't updated the documentation to reflect the new ".json" variables and the fact that the old ones are deprecated, so I did that just now.

Signed-off-by: Julie Vogelman <[email protected]>
Signed-off-by: Julie Vogelman <[email protected]>
@alexec alexec enabled auto-merge (squash) October 10, 2022 15:53
@alexec alexec disabled auto-merge October 10, 2022 15:53
@nikita-akuity
Copy link

nikita-akuity commented Oct 11, 2022

What happens if I already have a workflow parameter named 'json'? Can it cause backward compatibility issues?

@juliev0
Copy link
Contributor Author

juliev0 commented Oct 11, 2022

What happens if I already have a workflow parameter named 'json'? Can it cause backward compatibility issues?

It's a good question. I think we're okay, though. If you look at the changes in workflow/controller/operator.go, lines 585 and 587 occur after line 573, meaning that the user-defined "json" parameter should override the new "workflow.parameters.json".

Signed-off-by: Julie Vogelman <[email protected]>
Signed-off-by: Julie Vogelman <[email protected]>
Signed-off-by: Julie Vogelman <[email protected]>
Signed-off-by: Julie Vogelman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/templating Templating with `{{...}}`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expr expressions can't make use of workflow.parameters Error with expr from parameter output another step
6 participants