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

feat(route): Implements rewrite-target for ha-proxy #129

Merged
merged 1 commit into from Jul 31, 2020

Conversation

benoitf
Copy link
Contributor

@benoitf benoitf commented May 12, 2020

Annotation is haproxy.router.openshift.io/rewrite-target

Fixes openshift/origin#20474

documentation: openshift/openshift-docs#22021

This feature is also related to this enhancement: openshift/enhancements#287

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 12, 2020
@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 12, 2020
@openshift-ci-robot
Copy link
Contributor

Hi @benoitf. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@@ -439,6 +442,15 @@ backend {{genBackendNamePrefix $cfg.TLSTermination}}:{{$cfgIdx}}
http-request add-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
{{- end }}

{{- with $pathRewriteTarget := firstMatch $pathRewriteTargetPattern (index $cfg.Annotations "haproxy.router.openshift.io/rewrite-target") }}
# Path rewrite target
{{- if eq $pathRewriteTarget "/" }}

Choose a reason for hiding this comment

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

Why is this if required?

If we could leave it to a simple pattern without side effect, I believe it should help in the long term.

I may not be understanding why "/" is a special case though.

(Thanks for looking into this :) ).

Choose a reason for hiding this comment

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

Is it that we're trying to allow /$1 and / to do the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello,
it's to avoid the missing / or the double / in the final request to the backend server.

Copy link

Choose a reason for hiding this comment

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

https://haproxy-ingress.github.io/docs/configuration/keys/#rewrite-target doesn't seems to consider this a special case.

Copy link

Choose a reason for hiding this comment

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

I think I just understood what it meant... Line 2 and line 5 in the haproxy documentation example seems to consider it a special case to be handle only when you get "//" at the beginning so that the output is "/" at the begining. Those special case would be handled by the defautl behaviour of haproxy (point 1)

In here, we only handle the case where the rewrite path annotation would be "/" so that all traffic to the host only (i.e. http://endpoint) would still be routed correctly to the backend service (i.e. http://endpoint/). is that it? (Point2)

Choose a reason for hiding this comment

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

(I'm still wondering about Point2 being right or not for my own understanding XD. Awaiting your answer anxiously :) )

{{- with $pathRewriteTarget := firstMatch $pathRewriteTargetPattern (index $cfg.Annotations "haproxy.router.openshift.io/rewrite-target") }}
# Path rewrite target
{{- if eq $pathRewriteTarget "/" }}
http-request replace-path ^{{ $cfg.Path }}/?(.*)$ {{ $pathRewriteTarget }}\1
Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern looks suspicious. Suppose $cfg.Path were /foo, $pathRewriteTarget were /bar, and a client requested /foobar; would this rule rewrite the request to /barbar? I would expect the pattern to be something like this: ^{{ $cfg.Path }}(?:/(.*)|$)$. Similar applies to the pattern below.

Copy link
Contributor

Choose a reason for hiding this comment

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

^{{ $cfg.Path }}(?:/(.*)|$)$

Could probably be simplified to the following: ^{{ $cfg.Path }}(?:/(.*))?$.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Miciah about your first remark, if user has $pathRewriteTarget set to /bar it doesn't go in this if cause but in the else cause

Besides, in your example if client request /foobar it will not even reach the backend so we will not use at all this stuff.

it's because os_http_be.map file will contain something like
``^mydomain.com(:[0-9]+)?/foo(/.*)?$ be_http:default:example`

Choose a reason for hiding this comment

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

This is surprising to me as i would have expected the behaviour described by @Miciah to be true ;
Looking at the documentation provided by HAproxy regarding this annotation, one could expect that /foobar be replaced with /barbar when the annotation is set to /bar and the ingress path is /foo . (ref. line 5 in the table https://haproxy-ingress.github.io/docs/configuration/keys/#rewrite-target)

Ingress path | Request path | Rewrite target | Output
/foo | /foobar | /bar | /barbar

I wouldn't expect / to be treated differently in the frontend as it's part of the "path" string...

Now, I'm just giving my opinion from a user perspective... please don't mind it if this is something that should be addressed in the haproxy project... (I wouldn't know where to go to refer this as a potential design issue...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elafontaine : well if you specify route path being /foobar then you can play with annotation on it but if host of the route is only /foo then you can only play with /foo and /foo/something
another app could register a backend service with /foobar host

about /being handled differently, it's to act like nginx, haproxy and traefik rewrite-target annotations.

Choose a reason for hiding this comment

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

so I wouldn't be able to have /foobar still be redirected to /barbar because it wouldn't even be catched by the ingress resource as being part of /foo ingress path. Is my understanding right?

Choose a reason for hiding this comment

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

(it would make sense when you think of them as directory/file endpoint, but that's not how I was seeing it before :) )

@csantanapr
Copy link

How would I be able to do this without annotation in the Route resource?
Meaning what workarounds would you recommend to configure the haproxy using another method?

@csantanapr
Copy link

csantanapr commented Jul 23, 2020

We need this feature today and looking for ideas on how to do this in a cluster we are using OCP 4.4 on IBM Cloud managed.

@csantanapr
Copy link

This is for a customer that has a large application running on DIY kubernetes and using an ingress based on Nginx, and now moving to use OpenShift and trying to port the Ingress config to OCP Routes/haproxy

@Miciah
Copy link
Contributor

Miciah commented Jul 27, 2020

@benoitf, are you able to rebase the PR?

@Miciah
Copy link
Contributor

Miciah commented Jul 27, 2020

How would I be able to do this without annotation in the Route resource?
Meaning what workarounds would you recommend to configure the haproxy using another method?

There isn't a supported way. The only workaround I can think of at the moment would be to deploy the router using a custom deployment rather than using the operator.

Annotation is haproxy.router.openshift.io/rewrite-target
@benoitf
Copy link
Contributor Author

benoitf commented Jul 28, 2020

@Miciah rebased

@benoitf benoitf marked this pull request as ready for review July 28, 2020 07:18
@benoitf benoitf changed the title [WIP] feat(route): Implements rewrite-target for ha-proxy feat(route): Implements rewrite-target for ha-proxy Jul 28, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 28, 2020
@Miciah
Copy link
Contributor

Miciah commented Jul 28, 2020

Many thanks!
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: benoitf, Miciah

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2020
@benoitf
Copy link
Contributor Author

benoitf commented Jul 28, 2020

/retest

@openshift-ci-robot
Copy link
Contributor

@benoitf: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Miciah
Copy link
Contributor

Miciah commented Jul 28, 2020

Weird, the PR is already approved and lgtm'd, but...
/ok-to-test

@openshift-ci-robot openshift-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jul 28, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

19 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@Miciah
Copy link
Contributor

Miciah commented Jul 31, 2020

/test prow/images

@openshift-ci-robot
Copy link
Contributor

@Miciah: The specified target(s) for /test were not found.
The following commands are available to trigger jobs:

  • /test e2e
  • /test e2e-metal-ipi-router
  • /test e2e-upgrade
  • /test images
  • /test unit
  • /test verify

Use /test all to run the following jobs:

  • pull-ci-openshift-router-master-e2e
  • pull-ci-openshift-router-master-e2e-upgrade
  • pull-ci-openshift-router-master-images
  • pull-ci-openshift-router-master-unit
  • pull-ci-openshift-router-master-verify

In response to this:

/test prow/images

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Miciah
Copy link
Contributor

Miciah commented Jul 31, 2020

/test images

1 similar comment
@Miciah
Copy link
Contributor

Miciah commented Jul 31, 2020

/test images

@Miciah
Copy link
Contributor

Miciah commented Jul 31, 2020

/test e2e-upgrade

@Miciah
Copy link
Contributor

Miciah commented Jul 31, 2020

Last e2e failure looks related to BZ1857928 – [sig-operator] an end user use OLM can subscribe to the cockroachdb operator.
/test e2e

@openshift-merge-robot openshift-merge-robot merged commit df8e0cd into openshift:master Jul 31, 2020
@cutexx52
Copy link

This is for a customer that has a large application running on DIY kubernetes and using an ingress based on Nginx, and now moving to use OpenShift and trying to port the Ingress config to OCP Routes/haproxy

You could try using another Nginx as a reverse-proxy and write your own nginx.conf to do this. I am also surprised that the latest Openshift on IBM Cloud could not support rewrite-path by annotation.

@mhagnumdw
Copy link

This feature is available from which version of OpenShift?

@Miciah
Copy link
Contributor

Miciah commented Nov 16, 2020

It is in OpenShift 4.6.

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Openshift Route - missing path rewrite feature
9 participants