Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ API.
* [istio](pkg/i2gw/providers/istio/README.md)
* [gce](pkg/i2gw/providers/gce/README.md)
* [kong](pkg/i2gw/providers/kong/README.md)
* [nginx](pkg/i2gw/providers/nginx/README.md)
* [openapi](pkg/i2gw/providers/openapi3/README.md)

If your provider, or a specific feature, is not currently supported, please open
Expand Down
33 changes: 32 additions & 1 deletion cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/ingressnginx"
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/istio"
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/kong"
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/nginx"
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/openapi3"

// Call init for notifications
Expand Down Expand Up @@ -146,6 +147,21 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
}
}

for _, r := range gatewayResources {
resourceCount += len(r.GRPCRoutes)
for _, grpcRoute := range r.GRPCRoutes {
grpcRoute := grpcRoute
if grpcRoute.Annotations == nil {
grpcRoute.Annotations = make(map[string]string)
}
grpcRoute.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.Version)
err := pr.resourcePrinter.PrintObj(&grpcRoute, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s GRPCRoute: %v\n", grpcRoute.Name, err)
}
}
}

for _, r := range gatewayResources {
resourceCount += len(r.TLSRoutes)
for _, tlsRoute := range r.TLSRoutes {
Expand Down Expand Up @@ -191,6 +207,21 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
}
}

for _, r := range gatewayResources {
resourceCount += len(r.BackendTLSPolicies)
for _, backendTLSPolicy := range r.BackendTLSPolicies {
backendTLSPolicy := backendTLSPolicy
if backendTLSPolicy.Annotations == nil {
backendTLSPolicy.Annotations = make(map[string]string)
}
backendTLSPolicy.Annotations[i2gw.GeneratorAnnotationKey] = fmt.Sprintf("ingress2gateway-%s", i2gw.Version)
err := pr.resourcePrinter.PrintObj(&backendTLSPolicy, os.Stdout)
if err != nil {
fmt.Printf("# Error printing %s BackendTLSPolicy: %v\n", backendTLSPolicy.Name, err)
}
}
}

for _, r := range gatewayResources {
resourceCount += len(r.ReferenceGrants)
for _, referenceGrant := range r.ReferenceGrants {
Expand Down Expand Up @@ -277,7 +308,7 @@ func newPrintCommand() *cobra.Command {
var printFlags genericclioptions.JSONYamlPrintFlags
allowedFormats := printFlags.AllowedFormats()

// printCmd represents the print command. It prints HTTPRoutes and Gateways
// printCmd represents the print command. It prints Gateway API resources
// generated from Ingress resources.
var cmd = &cobra.Command{
Use: "print",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/onsi/gomega v1.33.0 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8=
github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk=
github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg=
github.com/onsi/gomega v1.33.0 h1:snPCflnZrpMsy94p4lXVEkHo12lmPnc3vY5XBbreexE=
github.com/onsi/gomega v1.33.0/go.mod h1:+925n5YtiFsLzzafLUHzVMBpvvRAzrydIBiSIxjX3wY=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
Expand Down
6 changes: 5 additions & 1 deletion pkg/i2gw/intermediate/intermediate_representation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/types"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1alpha3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

Expand All @@ -36,8 +37,10 @@ type IR struct {
TLSRoutes map[types.NamespacedName]gatewayv1alpha2.TLSRoute
TCPRoutes map[types.NamespacedName]gatewayv1alpha2.TCPRoute
UDPRoutes map[types.NamespacedName]gatewayv1alpha2.UDPRoute
GRPCRoutes map[types.NamespacedName]gatewayv1.GRPCRoute

ReferenceGrants map[types.NamespacedName]gatewayv1beta1.ReferenceGrant
BackendTLSPolicies map[types.NamespacedName]gatewayv1alpha3.BackendTLSPolicy
ReferenceGrants map[types.NamespacedName]gatewayv1beta1.ReferenceGrant
}

// GatewayContext contains the Gateway-API Gateway object and GatewayIR, which
Expand Down Expand Up @@ -90,4 +93,5 @@ type ProviderSpecificServiceIR struct {
Istio *IstioServiceIR
Kong *KongServiceIR
Openapi3 *Openapi3ServiceIR
Nginx *NginxServiceIR
}
21 changes: 21 additions & 0 deletions pkg/i2gw/intermediate/provider_nginx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2024 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 intermediate

type NginxGatewayIR struct{}
type NginxHTTPRouteIR struct{}
type NginxServiceIR struct{}
21 changes: 13 additions & 8 deletions pkg/i2gw/intermediate/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1alpha3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

Expand All @@ -38,14 +39,16 @@ import (
// This behavior is likely to change after https://github.com/kubernetes-sigs/gateway-api/pull/1863 takes place.
func MergeIRs(irs ...IR) (IR, field.ErrorList) {
mergedIRs := IR{
Gateways: make(map[types.NamespacedName]GatewayContext),
GatewayClasses: make(map[types.NamespacedName]gatewayv1.GatewayClass),
HTTPRoutes: make(map[types.NamespacedName]HTTPRouteContext),
Services: make(map[types.NamespacedName]ProviderSpecificServiceIR),
TLSRoutes: make(map[types.NamespacedName]gatewayv1alpha2.TLSRoute),
TCPRoutes: make(map[types.NamespacedName]gatewayv1alpha2.TCPRoute),
UDPRoutes: make(map[types.NamespacedName]gatewayv1alpha2.UDPRoute),
ReferenceGrants: make(map[types.NamespacedName]gatewayv1beta1.ReferenceGrant),
Gateways: make(map[types.NamespacedName]GatewayContext),
GatewayClasses: make(map[types.NamespacedName]gatewayv1.GatewayClass),
HTTPRoutes: make(map[types.NamespacedName]HTTPRouteContext),
Services: make(map[types.NamespacedName]ProviderSpecificServiceIR),
TLSRoutes: make(map[types.NamespacedName]gatewayv1alpha2.TLSRoute),
TCPRoutes: make(map[types.NamespacedName]gatewayv1alpha2.TCPRoute),
UDPRoutes: make(map[types.NamespacedName]gatewayv1alpha2.UDPRoute),
GRPCRoutes: make(map[types.NamespacedName]gatewayv1.GRPCRoute),
BackendTLSPolicies: make(map[types.NamespacedName]gatewayv1alpha3.BackendTLSPolicy),
ReferenceGrants: make(map[types.NamespacedName]gatewayv1beta1.ReferenceGrant),
}
var errs field.ErrorList
mergedIRs.Gateways, errs = mergeGatewayContexts(irs)
Expand All @@ -60,6 +63,8 @@ func MergeIRs(irs ...IR) (IR, field.ErrorList) {
maps.Copy(mergedIRs.TLSRoutes, gr.TLSRoutes)
maps.Copy(mergedIRs.TCPRoutes, gr.TCPRoutes)
maps.Copy(mergedIRs.UDPRoutes, gr.UDPRoutes)
maps.Copy(mergedIRs.GRPCRoutes, gr.GRPCRoutes)
maps.Copy(mergedIRs.BackendTLSPolicies, gr.BackendTLSPolicies)
maps.Copy(mergedIRs.ReferenceGrants, gr.ReferenceGrants)
}
return mergedIRs, errs
Expand Down
5 changes: 4 additions & 1 deletion pkg/i2gw/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1alpha3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

Expand Down Expand Up @@ -104,11 +105,13 @@ type GatewayResources struct {
GatewayClasses map[types.NamespacedName]gatewayv1.GatewayClass

HTTPRoutes map[types.NamespacedName]gatewayv1.HTTPRoute
GRPCRoutes map[types.NamespacedName]gatewayv1.GRPCRoute
TLSRoutes map[types.NamespacedName]gatewayv1alpha2.TLSRoute
TCPRoutes map[types.NamespacedName]gatewayv1alpha2.TCPRoute
UDPRoutes map[types.NamespacedName]gatewayv1alpha2.UDPRoute

ReferenceGrants map[types.NamespacedName]gatewayv1beta1.ReferenceGrant
BackendTLSPolicies map[types.NamespacedName]gatewayv1alpha3.BackendTLSPolicy
ReferenceGrants map[types.NamespacedName]gatewayv1beta1.ReferenceGrant

GatewayExtensions []unstructured.Unstructured
}
Expand Down
15 changes: 13 additions & 2 deletions pkg/i2gw/providers/common/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1alpha3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

// ToIR converts the received ingresses to intermediate.IR without taking into
Expand Down Expand Up @@ -66,8 +69,16 @@ func ToIR(ingresses []networkingv1.Ingress, servicePorts map[types.NamespacedNam
}

return intermediate.IR{
Gateways: gatewayByKey,
HTTPRoutes: routeByKey,
Gateways: gatewayByKey,
HTTPRoutes: routeByKey,
Services: make(map[types.NamespacedName]intermediate.ProviderSpecificServiceIR),
GatewayClasses: make(map[types.NamespacedName]gatewayv1.GatewayClass),
TLSRoutes: make(map[types.NamespacedName]gatewayv1alpha2.TLSRoute),
TCPRoutes: make(map[types.NamespacedName]gatewayv1alpha2.TCPRoute),
UDPRoutes: make(map[types.NamespacedName]gatewayv1alpha2.UDPRoute),
GRPCRoutes: make(map[types.NamespacedName]gatewayv1.GRPCRoute),
BackendTLSPolicies: make(map[types.NamespacedName]gatewayv1alpha3.BackendTLSPolicy),
ReferenceGrants: make(map[types.NamespacedName]gatewayv1beta1.ReferenceGrant),
}, nil
}

Expand Down
16 changes: 9 additions & 7 deletions pkg/i2gw/providers/common/gateway_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import (
// without taking into consideration any provider specific logic.
func ToGatewayResources(ir intermediate.IR) (i2gw.GatewayResources, field.ErrorList) {
gatewayResources := i2gw.GatewayResources{
Gateways: make(map[types.NamespacedName]gatewayv1.Gateway),
HTTPRoutes: make(map[types.NamespacedName]gatewayv1.HTTPRoute),
GatewayClasses: ir.GatewayClasses,
TLSRoutes: ir.TLSRoutes,
TCPRoutes: ir.TCPRoutes,
UDPRoutes: ir.UDPRoutes,
ReferenceGrants: ir.ReferenceGrants,
Gateways: make(map[types.NamespacedName]gatewayv1.Gateway),
HTTPRoutes: make(map[types.NamespacedName]gatewayv1.HTTPRoute),
GatewayClasses: ir.GatewayClasses,
GRPCRoutes: ir.GRPCRoutes,
TLSRoutes: ir.TLSRoutes,
TCPRoutes: ir.TCPRoutes,
UDPRoutes: ir.UDPRoutes,
BackendTLSPolicies: ir.BackendTLSPolicies,
ReferenceGrants: ir.ReferenceGrants,
}
for key, gatewayContext := range ir.Gateways {
gatewayResources.Gateways[key] = gatewayContext.Gateway
Expand Down
Loading