Merge pull request #5114 from whalecold/match

Feat: add header-pattern annotation.
This commit is contained in:
Kubernetes Prow Robot 2020-02-24 17:07:36 -08:00 committed by GitHub
commit 35264d6e8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 157 additions and 18 deletions

View file

@ -475,6 +475,120 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
})
})
ginkgo.Context("when canaried by header with value and pattern", func() {
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
"nginx.ingress.kubernetes.io/canary-by-header-pattern": "^Do[A-Z][a-z]+y$",
}
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
f.EnsureIngress(canaryIng)
ginkgo.By("routing requests to the canary upstream when header pattern is matched")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "DoCanary").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
ginkgo.By("routing requests to the mainline upstream when header failed to match header value")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "Docanary").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
})
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
"nginx.ingress.kubernetes.io/canary-by-header-value": "DoCanary",
"nginx.ingress.kubernetes.io/canary-by-header-pattern": "^Do[A-Z][a-z]+y$",
}
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
f.EnsureIngress(canaryIng)
ginkgo.By("routing requests to the mainline upstream when header is set to 'DoCananry' and header-value is 'DoCanary'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "DoCananry").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
})
ginkgo.It("should routes to mainline upstream when the given Regex causes error", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
"nginx.ingress.kubernetes.io/canary-by-header-pattern": "[][**da?$&*",
"nginx.ingress.kubernetes.io/canary-by-cookie": "CanaryByCookie",
}
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
f.EnsureIngress(canaryIng)
ginkgo.By("routing requests to the mainline upstream when the given Regex causes error")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "DoCanary").
WithCookie("CanaryByCookie", "always").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
})
})
ginkgo.Context("when canaried by header with value and cookie", func() {
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"