diff --git a/pkg/ingress/kube/annotations/canary.go b/pkg/ingress/kube/annotations/canary.go index 8f9173228..ce27bee88 100644 --- a/pkg/ingress/kube/annotations/canary.go +++ b/pkg/ingress/kube/annotations/canary.go @@ -154,7 +154,7 @@ func ApplyByHeader(canary, route *networking.HTTPRoute, canaryIngress *Ingress) match.Headers = map[string]*networking.StringMatch{ canaryConfig.Header: { MatchType: &networking.StringMatch_Regex{ - Regex: canaryConfig.HeaderPattern, + Regex: ".*" + canaryConfig.HeaderPattern + ".*", }, }, } diff --git a/test/e2e/conformance/tests/httproute-canary-header.go b/test/e2e/conformance/tests/httproute-canary-header.go index 9b952f051..794d6b234 100644 --- a/test/e2e/conformance/tests/httproute-canary-header.go +++ b/test/e2e/conformance/tests/httproute-canary-header.go @@ -34,6 +34,7 @@ var HTTPRouteCanaryHeader = suite.ConformanceTest{ testcases := []http.Assertion{ { Meta: http.AssertionMeta{ + TestCaseName: "case 1: canary header value matches", TargetBackend: "infra-backend-v1", TargetNamespace: "higress-conformance-infra", }, @@ -49,8 +50,10 @@ var HTTPRouteCanaryHeader = suite.ConformanceTest{ StatusCode: 200, }, }, - }, { + }, + { Meta: http.AssertionMeta{ + TestCaseName: "case 2: canary header value does not match", TargetBackend: "infra-backend-v2", TargetNamespace: "higress-conformance-infra", }, @@ -65,8 +68,10 @@ var HTTPRouteCanaryHeader = suite.ConformanceTest{ StatusCode: 200, }, }, - }, { + }, + { Meta: http.AssertionMeta{ + TestCaseName: "case 3: canary header value matches when the exact path matches", TargetBackend: "infra-backend-v2", TargetNamespace: "higress-conformance-infra", }, @@ -82,8 +87,10 @@ var HTTPRouteCanaryHeader = suite.ConformanceTest{ StatusCode: 200, }, }, - }, { + }, + { Meta: http.AssertionMeta{ + TestCaseName: "case 4: canary header value matches when the prefix path matches", TargetBackend: "infra-backend-v1", TargetNamespace: "higress-conformance-infra", }, @@ -102,6 +109,7 @@ var HTTPRouteCanaryHeader = suite.ConformanceTest{ }, { Meta: http.AssertionMeta{ + TestCaseName: "case 5: canary header value does not match when the exact path matches", TargetBackend: "infra-backend-v3", TargetNamespace: "higress-conformance-infra", }, @@ -119,6 +127,7 @@ var HTTPRouteCanaryHeader = suite.ConformanceTest{ }, { Meta: http.AssertionMeta{ + TestCaseName: "case 6: canary header value does not match when the prefix path matches", TargetBackend: "infra-backend-v3", TargetNamespace: "higress-conformance-infra", }, @@ -134,6 +143,87 @@ var HTTPRouteCanaryHeader = suite.ConformanceTest{ }, }, }, + { + Meta: http.AssertionMeta{ + TestCaseName: "case 7: canary header pattern matches", + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Path: "/baz", + Host: "canary.higress.io", + Headers: map[string]string{ + "traffic-split-higress": "test.com", + }, + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + }, + }, + }, + { + Meta: http.AssertionMeta{ + TestCaseName: "case 8: canary header pattern matches including the suffix", + TargetBackend: "infra-backend-v1", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Path: "/baz", + Host: "canary.higress.io", + Headers: map[string]string{ + "traffic-split-higress": "test.com.abc", + }, + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + }, + }, + }, + { + Meta: http.AssertionMeta{ + TestCaseName: "case 9: canary header is not set", + TargetBackend: "infra-backend-v2", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Path: "/baz", + Host: "canary.higress.io", + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + }, + }, + }, + { + Meta: http.AssertionMeta{ + TestCaseName: "case 10: canary header pattern does not match", + TargetBackend: "infra-backend-v2", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Path: "/baz", + Host: "canary.higress.io", + Headers: map[string]string{ + "traffic-split-higress": "test.org", + }, + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + }, + }, + }, } t.Run("Canary HTTPRoute Traffic Split", func(t *testing.T) { diff --git a/test/e2e/conformance/tests/httproute-canary-header.yaml b/test/e2e/conformance/tests/httproute-canary-header.yaml index f20ddc09c..9040a179b 100644 --- a/test/e2e/conformance/tests/httproute-canary-header.yaml +++ b/test/e2e/conformance/tests/httproute-canary-header.yaml @@ -109,3 +109,45 @@ spec: name: infra-backend-v3 port: number: 8080 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + nginx.ingress.kubernetes.io/canary: "true" + nginx.ingress.kubernetes.io/canary-by-header: "traffic-split-higress" + nginx.ingress.kubernetes.io/canary-by-header-pattern: "test.com" + name: ingress-baz-canary-pattern + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - host: canary.higress.io + http: + paths: + - path: /baz + pathType: Exact + backend: + service: + name: infra-backend-v1 + port: + number: 8080 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-baz + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - host: canary.higress.io + http: + paths: + - path: /baz + pathType: Exact + backend: + service: + name: infra-backend-v2 + port: + number: 8080