Skip to content

Commit 34304ec

Browse files
committed
Add converter in gce
1 parent 7afc205 commit 34304ec

File tree

9 files changed

+653
-40
lines changed

9 files changed

+653
-40
lines changed

pkg/i2gw/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type ResourceConverter interface {
7777

7878
// ImplementationSpecificHTTPPathTypeMatchConverter is an option to customize the ingress implementationSpecific
7979
// match type conversion.
80-
type ImplementationSpecificHTTPPathTypeMatchConverter func(*gatewayv1.HTTPPathMatch)
80+
type ImplementationSpecificHTTPPathTypeMatchConverter func(*gatewayv1.HTTPPathMatch) error
8181

8282
// ProviderImplementationSpecificOptions contains customized implementation-specific fields and functions.
8383
// These will be used by the common package to customize the provider-specific behavior for all the

pkg/i2gw/providers/common/converter.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
2424
networkingv1 "k8s.io/api/networking/v1"
25-
networkingv1beta1 "k8s.io/api/networking/v1beta1"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/runtime/schema"
2827
"k8s.io/apimachinery/pkg/types"
@@ -135,14 +134,8 @@ type ingressPath struct {
135134
}
136135

137136
func (a *ingressAggregator) addIngress(ingress networkingv1.Ingress) {
138-
var ingressClass string
139-
if ingress.Spec.IngressClassName != nil && *ingress.Spec.IngressClassName != "" {
140-
ingressClass = *ingress.Spec.IngressClassName
141-
} else if _, ok := ingress.Annotations[networkingv1beta1.AnnotationIngressClass]; ok {
142-
ingressClass = ingress.Annotations[networkingv1beta1.AnnotationIngressClass]
143-
} else {
144-
ingressClass = ingress.Name
145-
}
137+
ingressClass := GetIngressClass(ingress)
138+
146139
for _, rule := range ingress.Spec.Rules {
147140
a.addIngressRule(ingress.Namespace, ingress.Name, ingressClass, rule, ingress.Spec)
148141
}
@@ -377,7 +370,10 @@ func toHTTPRouteMatch(routePath networkingv1.HTTPIngressPath, path *field.Path,
377370
// is not given by the provider, an error is returned.
378371
case networkingv1.PathTypeImplementationSpecific:
379372
if toImplementationSpecificPathMatch != nil {
380-
toImplementationSpecificPathMatch(match.Path)
373+
err := toImplementationSpecificPathMatch(match.Path)
374+
if err != nil {
375+
return nil, field.Invalid(path.Child("pathType"), routePath.PathType, err.Error())
376+
}
381377
} else {
382378
return nil, field.Invalid(path.Child("pathType"), routePath.PathType, "implementationSpecific path type is not supported in generic translation, and your provider does not provide custom support to translate it")
383379
}

pkg/i2gw/providers/gce/converter.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package gce
1818

1919
import (
2020
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
21+
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common"
22+
networkingv1 "k8s.io/api/networking/v1"
23+
"k8s.io/apimachinery/pkg/util/validation/field"
2124
)
2225

2326
// converter implements the ToGatewayAPI function of i2gw.ResourceConverter interface.
@@ -32,11 +35,37 @@ type converter struct {
3235
func newConverter(conf *i2gw.ProviderConf) converter {
3336
return converter{
3437
conf: conf,
35-
featureParsers: []i2gw.FeatureParser{
36-
// The list of feature parsers comes here.
37-
},
38+
featureParsers: []i2gw.FeatureParser{},
3839
implementationSpecificOptions: i2gw.ProviderImplementationSpecificOptions{
39-
// The list of the implementationSpecific ingress fields options comes here.
40+
ToImplementationSpecificHTTPPathTypeMatch: implementationSpecificHTTPPathTypeMatch,
4041
},
4142
}
4243
}
44+
45+
func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.ErrorList) {
46+
ingressList := []networkingv1.Ingress{}
47+
for _, ing := range storage.Ingresses {
48+
ingressList = append(ingressList, *ing)
49+
}
50+
51+
// Convert plain ingress resources to gateway resources, ignoring all
52+
// provider-specific features.
53+
gatewayResources, errs := common.ToGateway(ingressList, c.implementationSpecificOptions)
54+
if len(errs) > 0 {
55+
return i2gw.GatewayResources{}, errs
56+
}
57+
58+
errs = toGceGatewayClass(ingressList, &gatewayResources)
59+
if len(errs) > 0 {
60+
return i2gw.GatewayResources{}, errs
61+
}
62+
63+
for _, parseFeatureFunc := range c.featureParsers {
64+
// Apply the feature parsing function to the gateway resources, one by one.
65+
parseErrs := parseFeatureFunc(ingressList, &gatewayResources)
66+
// Append the parsing errors to the error list.
67+
errs = append(errs, parseErrs...)
68+
}
69+
70+
return gatewayResources, errs
71+
}

0 commit comments

Comments
 (0)