Feat: canary supports using specific match strategy to match header value.

This commit is contained in:
Lisheng Zheng 2020-02-19 12:21:08 +08:00
parent 7d52174b51
commit 0b33650bb8
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"