Skip to content

Commit

Permalink
Add converter in gce
Browse files Browse the repository at this point in the history
  • Loading branch information
sawsa307 committed May 24, 2024
1 parent 7afc205 commit 34304ec
Show file tree
Hide file tree
Showing 9 changed files with 653 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pkg/i2gw/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type ResourceConverter interface {

// ImplementationSpecificHTTPPathTypeMatchConverter is an option to customize the ingress implementationSpecific
// match type conversion.
type ImplementationSpecificHTTPPathTypeMatchConverter func(*gatewayv1.HTTPPathMatch)
type ImplementationSpecificHTTPPathTypeMatchConverter func(*gatewayv1.HTTPPathMatch) error

// ProviderImplementationSpecificOptions contains customized implementation-specific fields and functions.
// These will be used by the common package to customize the provider-specific behavior for all the
Expand Down
16 changes: 6 additions & 10 deletions pkg/i2gw/providers/common/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -135,14 +134,8 @@ type ingressPath struct {
}

func (a *ingressAggregator) addIngress(ingress networkingv1.Ingress) {
var ingressClass string
if ingress.Spec.IngressClassName != nil && *ingress.Spec.IngressClassName != "" {
ingressClass = *ingress.Spec.IngressClassName
} else if _, ok := ingress.Annotations[networkingv1beta1.AnnotationIngressClass]; ok {
ingressClass = ingress.Annotations[networkingv1beta1.AnnotationIngressClass]
} else {
ingressClass = ingress.Name
}
ingressClass := GetIngressClass(ingress)

for _, rule := range ingress.Spec.Rules {
a.addIngressRule(ingress.Namespace, ingress.Name, ingressClass, rule, ingress.Spec)
}
Expand Down Expand Up @@ -377,7 +370,10 @@ func toHTTPRouteMatch(routePath networkingv1.HTTPIngressPath, path *field.Path,
// is not given by the provider, an error is returned.
case networkingv1.PathTypeImplementationSpecific:
if toImplementationSpecificPathMatch != nil {
toImplementationSpecificPathMatch(match.Path)
err := toImplementationSpecificPathMatch(match.Path)
if err != nil {
return nil, field.Invalid(path.Child("pathType"), routePath.PathType, err.Error())
}
} else {
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")
}
Expand Down
37 changes: 33 additions & 4 deletions pkg/i2gw/providers/gce/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package gce

import (
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
)

// converter implements the ToGatewayAPI function of i2gw.ResourceConverter interface.
Expand All @@ -32,11 +35,37 @@ type converter struct {
func newConverter(conf *i2gw.ProviderConf) converter {
return converter{
conf: conf,
featureParsers: []i2gw.FeatureParser{
// The list of feature parsers comes here.
},
featureParsers: []i2gw.FeatureParser{},
implementationSpecificOptions: i2gw.ProviderImplementationSpecificOptions{
// The list of the implementationSpecific ingress fields options comes here.
ToImplementationSpecificHTTPPathTypeMatch: implementationSpecificHTTPPathTypeMatch,

Check failure on line 40 in pkg/i2gw/providers/gce/converter.go

View workflow job for this annotation

GitHub Actions / goreleaser

cannot use implementationSpecificHTTPPathTypeMatch (value of type func(path *"sigs.k8s.io/gateway-api/apis/v1".HTTPPathMatch)) as i2gw.ImplementationSpecificHTTPPathTypeMatchConverter value in struct literal
},
}
}

func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.ErrorList) {
ingressList := []networkingv1.Ingress{}
for _, ing := range storage.Ingresses {
ingressList = append(ingressList, *ing)
}

// Convert plain ingress resources to gateway resources, ignoring all
// provider-specific features.
gatewayResources, errs := common.ToGateway(ingressList, c.implementationSpecificOptions)
if len(errs) > 0 {
return i2gw.GatewayResources{}, errs
}

errs = toGceGatewayClass(ingressList, &gatewayResources)
if len(errs) > 0 {
return i2gw.GatewayResources{}, errs
}

for _, parseFeatureFunc := range c.featureParsers {
// Apply the feature parsing function to the gateway resources, one by one.
parseErrs := parseFeatureFunc(ingressList, &gatewayResources)
// Append the parsing errors to the error list.
errs = append(errs, parseErrs...)
}

return gatewayResources, errs
}
Loading

0 comments on commit 34304ec

Please sign in to comment.