-
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
simplify customhttperrors e2e test and add regression test and fix a bug #3765
Merged
k8s-ci-robot
merged 2 commits into
kubernetes:master
from
ElvinEfendi:custom-http-error-bug-fix
Feb 14, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,20 +22,23 @@ import ( | |
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
extensions "k8s.io/api/extensions/v1beta1" | ||
|
||
"k8s.io/ingress-nginx/test/e2e/framework" | ||
) | ||
|
||
var _ = framework.IngressNginxDescribe("Annotations - custom-http-errors", func() { | ||
f := framework.NewDefaultFramework("custom-http-errors") | ||
|
||
BeforeEach(func() { | ||
f.NewEchoDeploymentWithReplicas(2) | ||
f.NewEchoDeploymentWithReplicas(1) | ||
}) | ||
|
||
AfterEach(func() { | ||
}) | ||
|
||
It("should set proxy_intercept_errors", func() { | ||
It("configures Nginx correctly", func() { | ||
host := "customerrors.foo.com" | ||
|
||
errorCodes := []string{"404", "500"} | ||
|
@@ -47,73 +50,51 @@ var _ = framework.IngressNginxDescribe("Annotations - custom-http-errors", func( | |
ing := framework.NewSingleIngress(host, "/", host, f.IngressController.Namespace, "http-svc", 80, &annotations) | ||
f.EnsureIngress(ing) | ||
|
||
f.WaitForNginxServer(host, | ||
func(server string) bool { | ||
return Expect(server).Should(ContainSubstring("proxy_intercept_errors on;")) | ||
}) | ||
}) | ||
var serverConfig string | ||
f.WaitForNginxServer(host, func(sc string) bool { | ||
serverConfig = sc | ||
return strings.Contains(serverConfig, fmt.Sprintf("server_name %s", host)) | ||
}) | ||
|
||
It("should create error routes", func() { | ||
host := "customerrors.foo.com" | ||
errorCodes := []string{"404", "500"} | ||
|
||
annotations := map[string]string{ | ||
"nginx.ingress.kubernetes.io/custom-http-errors": strings.Join(errorCodes, ","), | ||
} | ||
|
||
ing := framework.NewSingleIngress(host, "/test", host, f.IngressController.Namespace, "http-svc", 80, &annotations) | ||
f.EnsureIngress(ing) | ||
By("turning on proxy_intercept_errors directive") | ||
Expect(serverConfig).Should(ContainSubstring("proxy_intercept_errors on;")) | ||
|
||
By("configuring error_page directive") | ||
for _, code := range errorCodes { | ||
f.WaitForNginxServer(host, | ||
func(server string) bool { | ||
return Expect(server).Should(ContainSubstring(fmt.Sprintf("@custom_%s", code))) | ||
}) | ||
} | ||
}) | ||
|
||
It("should set up error_page routing", func() { | ||
host := "customerrors.foo.com" | ||
errorCodes := []string{"404", "500"} | ||
|
||
annotations := map[string]string{ | ||
"nginx.ingress.kubernetes.io/custom-http-errors": strings.Join(errorCodes, ","), | ||
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("error_page %s = @custom_%s", code, code))) | ||
} | ||
|
||
ing := framework.NewSingleIngress(host, "/test", host, f.IngressController.Namespace, "http-svc", 80, &annotations) | ||
f.EnsureIngress(ing) | ||
|
||
By("creating error locations") | ||
for _, code := range errorCodes { | ||
f.WaitForNginxServer(host, | ||
func(server string) bool { | ||
return Expect(server).Should(ContainSubstring(fmt.Sprintf("error_page %s = @custom_%s", code, code))) | ||
}) | ||
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("location @custom_%s", code))) | ||
} | ||
}) | ||
|
||
It("should create only one of each error route", func() { | ||
host := "customerrors.foo.com" | ||
errorCodes := [][]string{{"404", "500"}, {"400", "404"}} | ||
|
||
for i, codeSet := range errorCodes { | ||
annotations := map[string]string{ | ||
"nginx.ingress.kubernetes.io/custom-http-errors": strings.Join(codeSet, ","), | ||
By("updating configuration when only custom-http-error value changes") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the regression test covering bug. |
||
err := framework.UpdateIngress(f.KubeClientSet, f.IngressController.Namespace, host, func(ingress *extensions.Ingress) error { | ||
ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/custom-http-errors"] = "503" | ||
return nil | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
f.WaitForNginxServer(host, func(sc string) bool { | ||
if serverConfig != sc { | ||
serverConfig = sc | ||
return true | ||
} | ||
|
||
ing := framework.NewSingleIngress( | ||
fmt.Sprintf("%s-%d", host, i), fmt.Sprintf("/test-%d", i), | ||
host, f.IngressController.Namespace, "http-svc", 80, &annotations) | ||
f.EnsureIngress(ing) | ||
} | ||
|
||
for _, codeSet := range errorCodes { | ||
for _, code := range codeSet { | ||
f.WaitForNginxServer(host, | ||
func(server string) bool { | ||
count := strings.Count(server, fmt.Sprintf("location @custom_%s", code)) | ||
return Expect(count).Should(Equal(1)) | ||
}) | ||
} | ||
} | ||
return false | ||
}) | ||
Expect(serverConfig).Should(ContainSubstring("location @custom_503")) | ||
Expect(serverConfig).ShouldNot(ContainSubstring("location @custom_400")) | ||
Expect(serverConfig).ShouldNot(ContainSubstring("location @custom_500")) | ||
|
||
By("ignoring duplicate values (503 in this case) per server") | ||
annotations["nginx.ingress.kubernetes.io/custom-http-errors"] = "404, 503" | ||
ing = framework.NewSingleIngress(fmt.Sprintf("%s-else", host), "/else", host, f.IngressController.Namespace, "http-svc", 80, &annotations) | ||
f.EnsureIngress(ing) | ||
f.WaitForNginxServer(host, func(sc string) bool { | ||
serverConfig = sc | ||
return strings.Contains(serverConfig, "location /else") | ||
}) | ||
count := strings.Count(serverConfig, fmt.Sprintf("location @custom_503")) | ||
Expect(count).Should(Equal(1)) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Didn't know about this test format, much cleaner