Skip to content

Commit

Permalink
do not use /~ started path in Kong 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Nov 30, 2023
1 parent 5f8a1db commit ea518e9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/integration/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,15 @@ func TestIngressRewriteURI(t *testing.T) {
const (
jpegMagicNumber = "\xff\xd8\xff\xe0\x00\x10JFIF"
pngMagicNumber = "\x89PNG\r\n\x1a\n"

// Since Kong adds `~` prefix for regex paths from 3.0,
// we append `/~` to ingress paths if Kong major version >= 3.
addRegexPrefixMinimalMajorVersion = 3
pathRegexPrefix = "/~"
)

ctx := context.Background()
kongVersion := eventuallyGetKongVersion(t, proxyAdminURL)

ns, cleaner := helpers.Setup(ctx, t, env)

Expand Down Expand Up @@ -1302,7 +1308,11 @@ func TestIngressRewriteURI(t *testing.T) {

t.Logf("creating an Ingress for service %s with rewrite annotation", service.Name)
const serviceDomainRewrite = "rewrite.example"
ingressRewrite := generators.NewIngressForService("/~/foo/(.*)", map[string]string{
ingressPath := "/foo/(.*)"
if kongVersion.Major() >= addRegexPrefixMinimalMajorVersion {
ingressPath = pathRegexPrefix + ingressPath
}
ingressRewrite := generators.NewIngressForService(ingressPath, map[string]string{
annotations.AnnotationPrefix + annotations.StripPathKey: "true",
annotations.AnnotationPrefix + annotations.RewriteURIKey: "/image/$1",
}, service)
Expand Down Expand Up @@ -1335,8 +1345,13 @@ func TestIngressRewriteURI(t *testing.T) {
ingressRewrite, err = env.Cluster().Client().NetworkingV1().Ingresses(ns.Name).Get(ctx, ingressRewrite.Name, metav1.GetOptions{})
require.NoError(t, err)
t.Log("update the ingress capture group")
ingressPath = "/foo/(\\w+)/(.*)"
if kongVersion.Major() >= addRegexPrefixMinimalMajorVersion {
ingressPath = pathRegexPrefix + ingressPath
}

for i := range ingressRewrite.Spec.Rules {
ingressRewrite.Spec.Rules[i].HTTP.Paths[0].Path = "/~/foo/(\\w+)/(.*)"
ingressRewrite.Spec.Rules[i].HTTP.Paths[0].Path = ingressPath
}

_, err = env.Cluster().Client().NetworkingV1().Ingresses(ns.Name).Update(ctx, ingressRewrite, metav1.UpdateOptions{})
Expand Down

1 comment on commit ea518e9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: ea518e9 Previous: 73ab4d3 Ratio
BenchmarkDeckgenGenerateSHA - ns/op 71851 ns/op 29901 ns/op 2.40
BenchmarkDefaultContentToDBLessConfigConverter_Convert - ns/op 136 ns/op 71.27 ns/op 1.91

This comment was automatically generated by workflow using github-action-benchmark.

CC: @Kong/k8s-maintainers

Please sign in to comment.