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

Make string variable interpolation deterministic, and single-pass. #3024

Merged
merged 1 commit into from
Jul 31, 2020

Conversation

dlorenc
Copy link
Contributor

@dlorenc dlorenc commented Jul 28, 2020

Changes

Make string variable interpolation deterministic, and single-pass.

Right now we replace string variables one at a time, in an order governed by
iteration through a map[string]string. This has two implications:

  • We may expand variables twice. If one variable expands to another variable, that one may be expanded. And so on.
  • Whether or not this secondary expansion occurs (and even how it occurs!) can vary from run to run.

This commit changes to replace everything at once, using the strings.Replacer package.
It also adds a test to ensure replacements are stable and non-recursive.

See #2093

Note, we could go the other way this PR and instead embrace nested expansions. This one is simply my preference based on some reasons outlined in the issue.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

The variable interpolation algorithm has been changed. Nested expansion is no longer supported.
If you use replacements ( $(...) syntax) in your TaskRuns or PipelineRuns that resolve to secondary replacements, these will no longer work.

The algorithm is now deterministic and will result in the same expansion every run.

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jul 28, 2020
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 28, 2020
@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 28, 2020

Note that I'm not sure this is the best way to solve this issue. I could also easily be persuaded to correctly handle nested expansions, if we want to go that way. The important thing is that it's easy to describe and deterministic.

@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 28, 2020

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 28, 2020
@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 28, 2020

I'm also not sure how much of a "breaking change" this is. Nested expansions were never documented as working, and only worked sometimes. That said, if you were using them and got lucky, this would break you.

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/substitution/substitution.go 58.8% 60.7% 1.9

@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 28, 2020

/test pull-tekton-pipeline-integration-tests

Not seeing these failures locally, retrying

@dlorenc dlorenc force-pushed the deterministic-interpolation branch from 8f665e8 to 8257daa Compare July 28, 2020 15:57
Right now we replace string variables one at a time, in an order governed by
iteration through a map[string]string. This has two implications:
- We may expand variables twice. If one variable expands to another variable, that one may be expanded. And so on.
- Whether or not this secondary expansion occurs (and even how it occurs!) can vary from run to run.

This commit changes to replace everything at once, using the strings.Replacer package.
It also adds a test to ensure replacements are stable and non-recursiive.
@tekton-robot tekton-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 28, 2020
@dlorenc dlorenc force-pushed the deterministic-interpolation branch from 8257daa to 59ca59b Compare July 28, 2020 15:58
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/substitution/substitution.go 58.8% 60.4% 1.6

@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 28, 2020

Now with fewer regular expressions, and more passing tests!

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 29, 2020
@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 29, 2020

/hold I'm not actually sure if this is an API change or not and would like to discuss it a bit before merging.

@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 29, 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 Jul 29, 2020
@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 29, 2020

cc @skaegi who has ideas as discussed in the community meeting

@skaegi
Copy link
Contributor

skaegi commented Jul 29, 2020

I'm not at all opposed to making it single-pass for now! The current way we have it just leads to confusion.

With this fix in place, in the future we can add ordered deterministic param expansion without breaking backwards compatibility.

@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 29, 2020

With this fix in place, in the future we can add ordered deterministic param expansion without breaking backwards compatibility.

Ah, makes sense. Thanks for clarifying!

@bobcatfish
Copy link
Collaborator

I'm not actually sure if this is an API change or not and would like to discuss it a bit before merging.

I'm not sure either! I guess it depends on whether you view it as a bug or not ( i think @imjasonh has some kind of rule about that ). I think it is a bug, however it's also possible some folks are relying on this functionality even so.

My vote would be to go ahead and make the backwards incompatible change; if we wanted to be cautious we could have a release where we try to detect someone is using this functionality and warn them it's going to be removed?

@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 29, 2020

/hold cancel

Thanks!

@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 Jul 29, 2020
@dlorenc
Copy link
Contributor Author

dlorenc commented Jul 30, 2020

For my rationale on why I think this is ok:

  • Secondary expansion is definitely unintended behavior, but I wouldn't call it a bug.
  • The bug is the non-deterministic nature of the expansion.
  • It's not really possible to depend on this, since it's basically random.
  • Since it can't be depended on, we can change it.

@imjasonh
Copy link
Member

I agree it's a bug and we should feel free to change it.

If we want to support multi-pass interpolation we'll need to have a use case first, then a short TEP. :)

Thanks for catching this Dan!

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Thanks, nice catch!
/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: afrittoli

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 Jul 31, 2020
@tekton-robot tekton-robot merged commit 967492f into tektoncd:master Jul 31, 2020
@dlorenc dlorenc deleted the deterministic-interpolation branch August 1, 2020 01:32
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants