英文:
Regex doesnt work after kong upgrade to version 3.x
问题
正则表达式在将 Kong 升级到 3.x 版本后不起作用。
从 Kong 2.7 升级到 3.2 后,正则表达式停止起作用。
2.7 中使用的正则表达式模式:/payment/(docs|health)
3.2 中使用的正则表达式模式:/~payment/(docs|health)
也尝试过使用 ~/payment/(docs|health)
,但会出现如截图中的错误。
路径类型为 ImplementationSpecific
。
英文:
Regex doesnt work after kong upgrade to version 3.x.
After upgrading from kong 2.7 to 3.2, regex stopped working.
Regex pattern used in 2.7: /payment/(docs|health)
Regex pattern used in 3.2: /~payment/(docs|health)
Also tried to use ~/payment/(docs|health)
, but it gives error as in screenshot
Pathtype is ImplementationSpecific
- apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
labels:
app.kubernetes.io/name: payment-svc
name: payment-without-auth
namespace: payment
spec:
ingressClassName: kong
rules:
- host: abc.example.com
http:
paths:
- backend:
service:
name: payment-svc
port:
number: 80
path: /payment/(docs|health)
pathType: ImplementationSpecific
Tried couple if regex changes.
答案1
得分: 3
为了补充@kranthiveer-dontineni的回答,您需要在Kubernetes清单中使用/~
前缀来使其生效。
以
/~
开头的Ingress路径现在被视为正则表达式,并转换为以~
而不是/~
开头的Kong路由路径。为保留现有的转换,设置konghq.com/regex-prefix
为某个值。例如,如果您设置konghq.com/regex-prefix
:/@
,以/~
开头的路径将导致路由路径以/~
开头,而以/@
开头的路径将导致路由路径以~
开头。#2956
https://github.com/Kong/kubernetes-ingress-controller/blob/main/CHANGELOG.md#breaking-changes-1
英文:
To complement @kranthiveer-dontineni's answer, you'll need the /~
prefix in kubernetes manifests to make this work
> Ingress paths that begin with /~
are now treated as regular
> expressions, and are translated into a Kong route path that begins
> with ~ instead of /~
. To preserve the existing translation, set
> konghq.com/regex-prefix
to some value. For example, if you set
> konghq.com/regex-prefix
: /@
, paths beginning with /~
will result in
> route paths beginning in /~
, whereas paths beginning in /@
will result
> in route paths beginning in ~
. #2956
https://github.com/Kong/kubernetes-ingress-controller/blob/main/CHANGELOG.md#breaking-changes-1
答案2
得分: 0
如果您已经将您的Kong部署从2.8.X升级到3.0,数据库中的路由将自动添加前缀(~),从而导致路由数据库和配置文件之间的配置漂移,根据官方文档。
在使用状态文件更新数据库之前,使用deck convert命令将其转换为3.0格式。
**重要提示:**在将路径转换为3.0格式之前,不要在Kong Gateway 3.x上使用deck sync。这将破坏3.x中的所有正则表达式路由。
运行deck-convert来将您的2.x状态文件转换为3.x文件:
deck convert --from kong-gateway-2.x --to kong-gateway-3.x --input-file kong.yaml --output-file new-kong.yaml
**注意:**此内容摘自官方Kong文档。有关更多信息,请参考此链接。
英文:
If you have upgraded your kong deployment from 2.8.X to 3.0 the prefix(~) will be added to the routes in the database automatically and results in a configuration drift between the routes database and config file, as per the official documentation.
Before using your state files to update the database, convert them into the 3.0 format using the deck convert command.
Important: Don’t use deck sync with Kong Gateway 3.x before converting paths into the 3.0 format. This will break all regex routing in 3.x.
Run deck-convert against your 2.x state file to turn it into a 3.x file:
deck convert --from kong-gateway-2.x --to kong-gateway-3.x --input-file kong.yaml --output-file new-kong.yaml
Note: This content is taken from official kong documentation. Refer to this link for more information.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论