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 literal $ character work in set $location_path #3194

Merged

Conversation

bshelton229
Copy link
Contributor

@bshelton229 bshelton229 commented Oct 5, 2018

What this PR does / why we need it:

This is one option of making the template work when the literal $ character is in a path. We ran into this testing the new regex functionality where we have paths using regexes that contain a $.

I had a hard time finding another way to get a literal $ in a set variable in nginx. This idea was found in this thread - https://forum.nginx.org/read.php?2,218536,218559 .

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #3191

Special notes for your reviewer:

Using the geo module definitely feels really strange. When we were using a custom template to facilitate regex, before testing the use-regex functionality that will come in 0.20.0, we just removed the set $location_path declaration as it didn't appear to be used by the template anywhere else that we could see and we didn't need to use it anywhere custom. We also considered a string replace with something like %24 rather than this type of hack. There is possibly a better way to facilitate getting a $ character in a set that I can't find.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 5, 2018
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 5, 2018
@aledbf
Copy link
Member

aledbf commented Oct 7, 2018

@bshelton229 please rebase to pass CI

@bshelton229 bshelton229 force-pushed the literal-dollar-character branch from 95a5617 to 3dc131b Compare October 7, 2018 19:58
// geo $literal_dollar {
// default "$";
// }
func escapeLocationPathVar(input interface{}) string {
Copy link
Member

Choose a reason for hiding this comment

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

This is not necessarily about location path var and can be useful for other variables that might need to include $ in the value. What about escapeLiteralDollar?

@@ -834,3 +834,16 @@ func TestBuildUpstreamName(t *testing.T) {
}
}
}

func TestEscapeLocationPathVar(t *testing.T) {
escapedPath := escapeLocationPathVar("/$")
Copy link
Member

@ElvinEfendi ElvinEfendi Oct 8, 2018

Choose a reason for hiding this comment

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

Can you also add a test case for when there are multiple dollar signs in the string?

@bshelton229
Copy link
Contributor Author

@ElvinEfendi thanks! I made the suggested updates. I still haven't dug up a nicer way to escape dollar signs in nginx variables.

@ElvinEfendi
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 9, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bshelton229, ElvinEfendi

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 9, 2018
@ElvinEfendi
Copy link
Member

Thanks @bshelton229 ! I don't know any better option offhand either. So let's get this merged and we can change later when we find a better way of doing it.

@k8s-ci-robot k8s-ci-robot merged commit f56ab42 into kubernetes:master Oct 9, 2018
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
4 participants