Skip to content
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

Supports routing of modulo operation (mod) based on value of header #1841

Closed
lianglli opened this issue Aug 4, 2023 · 1 comment · Fixed by #1864
Closed

Supports routing of modulo operation (mod) based on value of header #1841

lianglli opened this issue Aug 4, 2023 · 1 comment · Fixed by #1864
Assignees

Comments

@lianglli
Copy link
Member

lianglli commented Aug 4, 2023

基于请求Header取模的流量切分,可以指定具体匹配的header,当header值取模运算得到余数满足关系运算符的匹配条件,则将请求转发到指定的upstream。

如果 [header值] mod [除数] 关系运算符 [余数] 为真,那么路由规则生效,请求就会被转发到指定的upstream。

取模除数: [2, 100]; 关系运算符: "==, >, >=, <, <="; 取模余数: [0, 取模除数)。

如果除数,关系运算符和余数的取值范围非法,则路由规则降级为基于请求Header的流量切分。

无损动态生效,无需tengine reload。

@lianglli lianglli added this to the 3.0.1 milestone Aug 4, 2023
@lianglli lianglli self-assigned this Aug 4, 2023
@lianglli lianglli removed this from the 3.0.1 milestone Sep 18, 2023
@lianglli
Copy link
Member Author

lianglli commented Nov 1, 2023

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-by-header: header-test2
    nginx.ingress.kubernetes.io/canary-mod-divisor: "100"
    nginx.ingress.kubernetes.io/canary-mod-relational-operator: ==
    nginx.ingress.kubernetes.io/canary-mod-remainder: "1"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
  creationTimestamp: "2023-10-31T07:02:17Z"
  generation: 1
  name: tengine-ingress-hello-header-mod-with-actions-ing
  namespace: default
  resourceVersion: "28173436"
  uid: bfe4bc3b-d384-4718-8a0a-5f6c3e89ab68
spec:
  ingressClassName: opensource-ingress
  rules:
  - host: echo.w1.com
    http:
      paths:
      - backend:
          service:
            name: tengine-ingress-echo2-service
            port:
              number: 80
        path: /
        pathType: Prefix
  tls:
  - hosts:
    - echo.w1.com
    secretName: https-server-1
status:
  loadBalancer:
    ingress:
    - {}

........................................................................

$ curl -i -k -H "header-test2: 1001" https://echo.w1.com
HTTP/2 200 
server: Tengine/3.1.0
date: Wed, 01 Nov 2023 09:21:14 GMT
content-type: text/plain; charset=utf-8
content-length: 7
test-result: B0-236-564-29122
test-host: echo.w1.com
strict-transport-security: max-age=0
ups-target-key: default-tengine-ingress-echo2-service-80
x-protocol: HTTP/2.0
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

echo ok

@lianglli lianglli closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant