Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/i2gw/providers/ingressnginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The project supports translating ingress-nginx specific annotations.

To specify the name of the Ingress class to select, use `--ingress-nginx-ingress-class=ingress-nginx` (default to 'nginx').

**ImplementationSpecific Path Type**

The ingress-nginx provider supports the `ImplementationSpecific` path type. When this path type is used, paths are converted to `PathMatchRegularExpression` in the Gateway API HTTPRoute, as ingress-nginx treats ImplementationSpecific paths as regular expressions.

Current supported annotations:

- `nginx.ingress.kubernetes.io/canary`: If set to true will enable weighting backends.
Expand Down
8 changes: 6 additions & 2 deletions pkg/i2gw/providers/ingressnginx/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (

// resourcesToIRConverter implements the ToIR function of i2gw.ResourcesToIRConverter interface.
type resourcesToIRConverter struct {
featureParsers []i2gw.FeatureParser
featureParsers []i2gw.FeatureParser
implementationSpecificOptions i2gw.ProviderImplementationSpecificOptions
}

// newResourcesToIRConverter returns an ingress-nginx resourcesToIRConverter instance.
Expand All @@ -34,6 +35,9 @@ func newResourcesToIRConverter() *resourcesToIRConverter {
featureParsers: []i2gw.FeatureParser{
canaryFeature,
},
implementationSpecificOptions: i2gw.ProviderImplementationSpecificOptions{
ToImplementationSpecificHTTPPathTypeMatch: implementationSpecificHTTPPathTypeMatch,
},
}
}

Expand All @@ -44,7 +48,7 @@ func (c *resourcesToIRConverter) convert(storage *storage) (intermediate.IR, fie

// Convert plain ingress resources to gateway resources, ignoring all
// provider-specific features.
ir, errs := common.ToIR(ingressList, storage.ServicePorts, i2gw.ProviderImplementationSpecificOptions{})
ir, errs := common.ToIR(ingressList, storage.ServicePorts, c.implementationSpecificOptions)
if len(errs) > 0 {
return intermediate.IR{}, errs
}
Expand Down
56 changes: 48 additions & 8 deletions pkg/i2gw/providers/ingressnginx/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/ptr"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

Expand Down Expand Up @@ -337,15 +336,56 @@ func Test_ToIR(t *testing.T) {
},
},
},
expectedIR: intermediate.IR{},
expectedErrors: field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "spec.rules[0].http.paths[0].pathType",
BadValue: ptr.To("ImplementationSpecific"),
Detail: "implementationSpecific path type is not supported in generic translation, and your provider does not provide custom support to translate it",
expectedIR: intermediate.IR{
Gateways: map[types.NamespacedName]intermediate.GatewayContext{
{Namespace: "default", Name: "ingress-nginx"}: {
Gateway: gatewayv1.Gateway{
ObjectMeta: metav1.ObjectMeta{Name: "ingress-nginx", Namespace: "default"},
Spec: gatewayv1.GatewaySpec{
GatewayClassName: "ingress-nginx",
Listeners: []gatewayv1.Listener{{
Name: "test-mydomain-com-http",
Port: 80,
Protocol: gatewayv1.HTTPProtocolType,
Hostname: ptrTo(gatewayv1.Hostname("test.mydomain.com")),
}},
},
},
},
},
HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{
{Namespace: "default", Name: "implementation-specific-regex-test-mydomain-com"}: {
HTTPRoute: gatewayv1.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{Name: "implementation-specific-regex-test-mydomain-com", Namespace: "default"},
Spec: gatewayv1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1.CommonRouteSpec{
ParentRefs: []gatewayv1.ParentReference{{
Name: "ingress-nginx",
}},
},
Hostnames: []gatewayv1.Hostname{"test.mydomain.com"},
Rules: []gatewayv1.HTTPRouteRule{{
Matches: []gatewayv1.HTTPRouteMatch{{
Path: &gatewayv1.HTTPPathMatch{
Type: ptrTo(gatewayv1.PathMatchRegularExpression),
Value: ptrTo("/~/echo/**/test"),
},
}},
BackendRefs: []gatewayv1.HTTPBackendRef{{
BackendRef: gatewayv1.BackendRef{
BackendObjectReference: gatewayv1.BackendObjectReference{
Name: "test",
Port: ptrTo(gatewayv1.PortNumber(80)),
},
},
}},
}},
},
},
},
},
},
expectedErrors: field.ErrorList{},
},
{
name: "multiple rules with TLS",
Expand Down
29 changes: 29 additions & 0 deletions pkg/i2gw/providers/ingressnginx/implementation_specific.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package ingressnginx

import (
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// implementationSpecificHTTPPathTypeMatch handles the ImplementationSpecific path type
// for ingress-nginx. When ImplementationSpecific is used, ingress-nginx treats paths
// as regular expressions, so we convert them to PathMatchRegularExpression.
func implementationSpecificHTTPPathTypeMatch(path *gatewayv1.HTTPPathMatch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only true if `nginx.ingress.kubernetes.io/use-regex: "true"

pmRegex := gatewayv1.PathMatchRegularExpression
path.Type = &pmRegex
}
67 changes: 67 additions & 0 deletions pkg/i2gw/providers/ingressnginx/implementation_specific_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package ingressnginx

import (
"testing"

"github.com/stretchr/testify/assert"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

func Test_implementationSpecificHTTPPathTypeMatch(t *testing.T) {
testCases := []struct {
name string
inputPath string
expectedType gatewayv1.PathMatchType
expectedValue string
}{
{
name: "regex path with wildcard",
inputPath: "/.*/execution/.*",
expectedType: gatewayv1.PathMatchRegularExpression,
expectedValue: "/.*/execution/.*",
},
{
name: "regex path with specific pattern",
inputPath: "/api/v3/amp/login.*",
expectedType: gatewayv1.PathMatchRegularExpression,
expectedValue: "/api/v3/amp/login.*",
},
{
name: "simple path",
inputPath: "/page/track.*",
expectedType: gatewayv1.PathMatchRegularExpression,
expectedValue: "/page/track.*",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
path := &gatewayv1.HTTPPathMatch{
Value: &tc.inputPath,
}

implementationSpecificHTTPPathTypeMatch(path)

assert.NotNil(t, path.Type)
assert.Equal(t, tc.expectedType, *path.Type)
assert.NotNil(t, path.Value)
assert.Equal(t, tc.expectedValue, *path.Value)
})
}
}