Skip to content

Commit 90a2357

Browse files
committed
feat: deprecate i2gw.InputResources
Signed-off-by: Liang Deng <[email protected]>
1 parent 63d1176 commit 90a2357

20 files changed

+172
-188
lines changed

pkg/i2gw/ingress2gateway.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ func ToGatewayAPIResources(ctx context.Context, namespace string, inputFile stri
6868
errs field.ErrorList
6969
)
7070
for _, provider := range providerByName {
71-
// TODO(#113) Remove input resources from ToGatewayAPI function
72-
providerGatewayResources, conversionErrs := provider.ToGatewayAPI(InputResources{})
71+
providerGatewayResources, conversionErrs := provider.ToGatewayAPI()
7372
errs = append(errs, conversionErrs...)
7473
gatewayResources = append(gatewayResources, providerGatewayResources)
7574
}

pkg/i2gw/provider.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ type CustomResourceReader interface {
6969
// conversion functions.
7070
type ResourceConverter interface {
7171

72-
// ToGatewayAPIResources converts the received InputResources associated
72+
// ToGatewayAPIResources converts stored API entities associated
7373
// with the Provider into GatewayResources.
74-
ToGatewayAPI(resources InputResources) (GatewayResources, field.ErrorList)
74+
ToGatewayAPI() (GatewayResources, field.ErrorList)
7575
}
7676

7777
// ImplementationSpecificHTTPPathTypeMatchConverter is an option to customize the ingress implementationSpecific
@@ -85,11 +85,6 @@ type ProviderImplementationSpecificOptions struct {
8585
ToImplementationSpecificHTTPPathTypeMatch ImplementationSpecificHTTPPathTypeMatchConverter
8686
}
8787

88-
// InputResources contains all Ingress objects.
89-
type InputResources struct {
90-
Ingresses []networkingv1.Ingress
91-
}
92-
9388
// GatewayResources contains all Gateway-API objects.
9489
type GatewayResources struct {
9590
Gateways map[types.NamespacedName]gatewayv1.Gateway
@@ -103,9 +98,9 @@ type GatewayResources struct {
10398
ReferenceGrants map[types.NamespacedName]gatewayv1alpha2.ReferenceGrant
10499
}
105100

106-
// FeatureParser is a function that reads the InputResources, and applies
101+
// FeatureParser is a function that reads the Ingresses, and applies
107102
// the appropriate modifications to the GatewayResources.
108103
//
109104
// Different FeatureParsers will run in undetermined order. The function must
110105
// modify / create only the required fields of the gateway resources and nothing else.
111-
type FeatureParser func(InputResources, *GatewayResources) field.ErrorList
106+
type FeatureParser func([]networkingv1.Ingress, *GatewayResources) field.ErrorList

pkg/i2gw/providers/apisix/apisix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ func NewProvider(conf *i2gw.ProviderConf) i2gw.Provider {
4848
}
4949
}
5050

51-
// ToGatewayAPI converts the received i2gw.InputResources to i2gw.GatewayResources
51+
// ToGatewayAPI converts stored Apisix API entities to i2gw.GatewayResources
5252
// including the apisix specific features.
53-
func (p *Provider) ToGatewayAPI(_ i2gw.InputResources) (i2gw.GatewayResources, field.ErrorList) {
53+
func (p *Provider) ToGatewayAPI() (i2gw.GatewayResources, field.ErrorList) {
5454
return p.converter.convert(p.storage)
5555
}
5656

pkg/i2gw/providers/apisix/converter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.Erro
5555

5656
for _, parseFeatureFunc := range c.featureParsers {
5757
// Apply the feature parsing function to the gateway resources, one by one.
58-
parseErrs := parseFeatureFunc(i2gw.InputResources{Ingresses: ingressList}, &gatewayResources)
58+
parseErrs := parseFeatureFunc(ingressList, &gatewayResources)
5959
// Append the parsing errors to the error list.
6060
errs = append(errs, parseErrs...)
6161
}

pkg/i2gw/providers/apisix/http_to_https.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ package apisix
1919
import (
2020
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
2121
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common"
22+
networkingv1 "k8s.io/api/networking/v1"
2223
"k8s.io/apimachinery/pkg/types"
2324
"k8s.io/apimachinery/pkg/util/validation/field"
2425
"k8s.io/utils/ptr"
2526
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2627
)
2728

28-
func httpToHTTPSFeature(ingressResources i2gw.InputResources, gatewayResources *i2gw.GatewayResources) field.ErrorList {
29+
func httpToHTTPSFeature(ingresses []networkingv1.Ingress, gatewayResources *i2gw.GatewayResources) field.ErrorList {
2930
var errs field.ErrorList
3031
httpToHTTPSAnnotation := apisixAnnotation("http-to-https")
31-
ruleGroups := common.GetRuleGroups(ingressResources.Ingresses)
32+
ruleGroups := common.GetRuleGroups(ingresses)
3233
for _, rg := range ruleGroups {
3334
for _, rule := range rg.Rules {
3435
if val := rule.Ingress.Annotations[httpToHTTPSAnnotation]; val == "true" {

pkg/i2gw/providers/apisix/http_to_https_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,14 @@ func Test_httpToHttpsFeature(t *testing.T) {
257257

258258
for _, tc := range testCases {
259259
t.Run(tc.name, func(t *testing.T) {
260-
ingressResources := i2gw.InputResources{
261-
Ingresses: []networkingv1.Ingress{tc.ingress},
262-
}
260+
ingresses := []networkingv1.Ingress{tc.ingress}
263261
gatewayResources := &i2gw.GatewayResources{
264262
HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{
265263
{Name: tc.expectedHTTPRoute.Name, Namespace: tc.expectedHTTPRoute.Namespace}: *tc.initialHTTPRoute,
266264
},
267265
}
268266

269-
errs := httpToHTTPSFeature(ingressResources, gatewayResources)
267+
errs := httpToHTTPSFeature(ingresses, gatewayResources)
270268

271269
if len(errs) != len(tc.expectedError) {
272270
t.Errorf("expected %d errors, got %d", len(tc.expectedError), len(errs))

pkg/i2gw/providers/ingressnginx/canary.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3030
)
3131

32-
func canaryFeature(ingressResources i2gw.InputResources, gatewayResources *i2gw.GatewayResources) field.ErrorList {
33-
ruleGroups := common.GetRuleGroups(ingressResources.Ingresses)
32+
func canaryFeature(ingresses []networkingv1.Ingress, gatewayResources *i2gw.GatewayResources) field.ErrorList {
33+
ruleGroups := common.GetRuleGroups(ingresses)
3434

3535
for _, rg := range ruleGroups {
3636
ingressPathsByMatchKey, errs := getPathsByMatchGroups(rg)

pkg/i2gw/providers/ingressnginx/converter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.Erro
5454

5555
for _, parseFeatureFunc := range c.featureParsers {
5656
// Apply the feature parsing function to the gateway resources, one by one.
57-
parseErrs := parseFeatureFunc(i2gw.InputResources{Ingresses: ingressList}, &gatewayResources)
57+
parseErrs := parseFeatureFunc(ingressList, &gatewayResources)
5858
// Append the parsing errors to the error list.
5959
errs = append(errs, parseErrs...)
6060
}

pkg/i2gw/providers/ingressnginx/converter_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ func Test_ToGateway(t *testing.T) {
218218
nginxProvider := provider.(*Provider)
219219
nginxProvider.storage.Ingresses = tc.ingresses
220220

221-
// TODO(#113) we pass an empty i2gw.InputResources temporarily until we change ToGatewayAPI function on the interface
222-
gatewayResources, errs := provider.ToGatewayAPI(i2gw.InputResources{})
221+
gatewayResources, errs := provider.ToGatewayAPI()
223222

224223
if len(errs) != len(tc.expectedErrors) {
225224
t.Errorf("Expected %d errors, got %d: %+v", len(tc.expectedErrors), len(errs), errs)

pkg/i2gw/providers/ingressnginx/ingressnginx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ func NewProvider(conf *i2gw.ProviderConf) i2gw.Provider {
4848
}
4949
}
5050

51-
// ToGatewayAPI converts the received i2gw.InputResources to i2gw.GatewayResources
51+
// ToGatewayAPI converts stored Ingress-Nginx API entities to i2gw.GatewayResources
5252
// including the ingress-nginx specific features.
53-
func (p *Provider) ToGatewayAPI(_ i2gw.InputResources) (i2gw.GatewayResources, field.ErrorList) {
53+
func (p *Provider) ToGatewayAPI() (i2gw.GatewayResources, field.ErrorList) {
5454
return p.converter.convert(p.storage)
5555
}
5656

0 commit comments

Comments
 (0)