-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Added permanent-redirect-code #2834
Conversation
/assign @aledbf |
Codecov Report
@@ Coverage Diff @@
## master #2834 +/- ##
==========================================
+ Coverage 47.34% 47.56% +0.21%
==========================================
Files 75 76 +1
Lines 5413 5489 +76
==========================================
+ Hits 2563 2611 +48
- Misses 2525 2540 +15
- Partials 325 338 +13
Continue to review full report at Codecov.
|
Works a treat, without the code annotation:
With the code annotation:
Could we get this merged? |
at least 2 weeks Edit: you can check the status here https://github.com/kubernetes/ingress-nginx/projects/25 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall 👍
@@ -366,6 +367,10 @@ To configure this setting globally for all Ingress rules, the `limit-rate-after` | |||
|
|||
This annotation allows to return a permanent redirect instead of sending data to the upstream. For example `nginx.ingress.kubernetes.io/permanent-redirect: https://www.google.com` would redirect everything to Google. | |||
|
|||
### Permanent Redirect Code | |||
|
|||
This annotation allows you to modify the status code used for permanent redirects. For example `nginx.ingress.kubernetes.io/permanent-redirect-code: 301` would return your redirect with a 301. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations can't be int, you have to use single quotes around numeric values.
@@ -73,14 +74,28 @@ func (a redirect) Parse(ing *extensions.Ingress) (interface{}, error) { | |||
return nil, err | |||
} | |||
|
|||
prc, err := parser.GetStringAnnotation("permanent-redirect-code", ing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe an int would be more suitable, no need to call Atoi
then.
} | ||
|
||
var prci = http.StatusPermanentRedirect | ||
if prc != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do use an int
, the validation of the annotation could be something like
// this is set at the top of the file
const defaultPermanentRedirectCode = http.StatusPermanentRedirect
if prc < http.StatusMultipleChoices || prc > http.StatusPermanentRedirect {
prc = defaultPermanentRedirectCode
}
(depending on what HTTP codes you believe are appropriate).
The const just makes the code mode readable, but more importantly you don't need 2 variables anymore.
Hey @antoineco - I've pushed pushed your suggestions, however one thing that doesn't sit right with me is that i have renamed the annotation to However, I didn't want to make such a breaking change without understanding what, if any strategy you have for depreciating annotations. |
@@ -73,14 +73,25 @@ func (a redirect) Parse(ing *extensions.Ingress) (interface{}, error) { | |||
return nil, err | |||
} | |||
|
|||
const defaultPermanentRedirectCode = http.StatusPermanentRedirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default should remain http.StatusMovedPermanently for backward compatibility reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this right above the definition of the Config struct, defaults should be clearly visible.
@Stono thanks for addressing my comments. You're completely right about the naming, we should not put the name of the http code inside the annotation name if the code is configurable. I'd discuss the renaming of existing annotations in a different PR though, because, as you said, this change would be breaking backward compatibility unless we keep supporting the old and new annotations side by side for a little while. |
@antoineco that's done, if you're happy i'd like to get this merged to ensure it's in the next release as it's super critical for me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good but we need a simple unit test for it before merging.
I'll add the corresponding e2e test as soon as you're done.
return nil, err | ||
} | ||
|
||
const defaultPermanentRedirectCode = http.StatusMovedPermanently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the const declaration after the import
block as suggested before, otherwise there is little value in declaring a default as a constant.
@@ -43,6 +43,7 @@ You can add these Kubernetes annotations to specific Ingress objects to customiz | |||
|[nginx.ingress.kubernetes.io/limit-connections](#rate-limiting)|number| | |||
|[nginx.ingress.kubernetes.io/limit-rps](#rate-limiting)|number| | |||
|[nginx.ingress.kubernetes.io/permanent-redirect](#permanent-redirect)|string| | |||
|[nginx.ingress.kubernetes.io/permanent-redirect-code](#permanent-redirect-code)|number| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated annotation name.
Answer to deleted comment Saddened to read that. Both my comments were already mentioned before, you could have addressed them right away, in a single round trip. All features need a test before we can merge them, I'm kindly referring you to the contribution guidelines. If you felt the original name was more aligned with the feature I would have been happy to let you convince me, reviews are a discussion. As a reviewer I do have to question why names do not follow the existing scheme, but I doesn't mean this can't be challenged. |
Answer to deleted comment You said you're not familiar with Go so I tried to help and share precise directions and good practices. A bit unfair to come and blame the reviewers afterwards for introducing confusion, isn't it? I didn't make you use any name, I asked you about your opinion. Re-read my answer above. Again, please check the contribution guidelines and show more empathy next time. We all try to help and deliver good software, and we all do it purely on our free time. |
@Stono e2e tests are here: [PATCH] Add e2e test for redirect annotations Tests assume the annotation is called edit: I already spotted a bug without even running the test.
|
Hey, |
The choice is yours, both make sense to me according to what was discussed already. |
I've moved back to I've just added you as a collaborator on my fork rather than messing about with patches. |
/assign antoineco E2E tests are still failing because 404 is always returned. I'll investigate later. |
Thanks @antoineco |
Minor refactoring of parser and unit tests
Found it. It was a simple misuse of the /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: antoineco, Stono 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 |
Hey,
This PR addresses #2715 (I hope).
It makes the permanent redirect code 308 by default (as this is more aligned to a permanent redirect) but also gives the ability to override it.
<< Golang noob... so check with caution
Please could you do me a build so I can test it out?