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 1e4c4a9 commit c58ad98
Show file tree
Hide file tree
Showing 7 changed files with 693 additions and 37 deletions.
11 changes: 2 additions & 9 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
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,
},
}
}

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 c58ad98

Please sign in to comment.