Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Mar 11, 2024
1 parent 33ef061 commit 72cfb9e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
7 changes: 2 additions & 5 deletions pkg/i2gw/providers/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package common
import (
"fmt"
"regexp"
"strings"

networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
Expand Down Expand Up @@ -102,11 +103,7 @@ func NameFromHost(host string) string {
}

func RouteName(ingressName, host string) string {
routeName := ingressName
if host != "" {
routeName = fmt.Sprintf("%s-%s", ingressName, NameFromHost(host))
}
return routeName
return strings.TrimSuffix(fmt.Sprintf("%s-%s", ingressName, NameFromHost(host)))

Check failure on line 106 in pkg/i2gw/providers/common/utils.go

View workflow job for this annotation

GitHub Actions / goreleaser

not enough arguments in call to strings.TrimSuffix
}

func ToBackendRef(ib networkingv1.IngressBackend, path *field.Path) (*gatewayv1.BackendRef, *field.Error) {
Expand Down
13 changes: 6 additions & 7 deletions pkg/i2gw/providers/kong/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"

"k8s.io/apimachinery/pkg/runtime/schema"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

const (
Expand All @@ -32,19 +31,19 @@ const (
)

const (
v1beta1Version string = "v1beta1"
v1beta1Version = "v1beta1"

kongResourcesGroup gatewayv1beta1.Group = "configuration.konghq.com"
kongResourcesGroup = "configuration.konghq.com"

kongPluginKind gatewayv1beta1.Kind = "KongPlugin"
tcpIngressKind gatewayv1beta1.Kind = "TCPIngress"
kongPluginKind = "KongPlugin"
tcpIngressKind = "TCPIngress"
)

var (
tcpIngressGVK = schema.GroupVersionKind{
Group: string(kongResourcesGroup),
Group: kongResourcesGroup,
Version: v1beta1Version,
Kind: string(tcpIngressKind),
Kind: tcpIngressKind,
}
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/i2gw/providers/kong/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func Test_ToGateway(t *testing.T) {
{
Type: gatewayv1.HTTPRouteFilterExtensionRef,
ExtensionRef: &gatewayv1.LocalObjectReference{
Group: kongResourcesGroup,
Kind: kongPluginKind,
Group: gatewayv1.Group(kongResourcesGroup),
Kind: gatewayv1.Kind(kongPluginKind),
Name: gatewayv1.ObjectName("plugin1"),
},
},
Expand Down
5 changes: 1 addition & 4 deletions pkg/i2gw/providers/kong/kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func init() {

// Provider implements the i2gw.Provider interface.
type Provider struct {
conf *i2gw.ProviderConf
storage storage

*resourceReader
Expand All @@ -44,8 +43,6 @@ type Provider struct {
// NewProvider constructs and returns the kong implementation of i2gw.Provider.
func NewProvider(conf *i2gw.ProviderConf) i2gw.Provider {
return &Provider{
conf: conf,

resourceReader: newResourceReader(conf),
converter: newConverter(),
}
Expand All @@ -54,7 +51,7 @@ func NewProvider(conf *i2gw.ProviderConf) i2gw.Provider {
// ToGatewayAPI converts the received i2gw.InputResources to i2gw.GatewayResources
// including the kong specific features.
func (p *Provider) ToGatewayAPI(_ i2gw.InputResources) (i2gw.GatewayResources, field.ErrorList) {
return p.convert(p.storage)
return p.converter.convert(p.storage)
}

func (p *Provider) ReadResourcesFromCluster(ctx context.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/i2gw/providers/kong/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func parsePluginsAnnotation(annotations map[string]string) []gatewayv1.HTTPRoute
filters = append(filters, gatewayv1.HTTPRouteFilter{
Type: gatewayv1.HTTPRouteFilterExtensionRef,
ExtensionRef: &gatewayv1.LocalObjectReference{
Group: kongResourcesGroup,
Kind: kongPluginKind,
Group: gatewayv1.Group(kongResourcesGroup),
Kind: gatewayv1.Kind(kongPluginKind),
Name: gatewayv1.ObjectName(v),
},
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/i2gw/providers/kong/resource_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newResourceReader(conf *i2gw.ProviderConf) *resourceReader {
// -----------------------------------------------------------------------------

func (r *resourceReader) readResourcesFromCluster(ctx context.Context) (*storage, error) {
st := newStorage()
st := newResourceStorage()

ingresses, err := common.ReadIngressesFromCluster(ctx, r.conf.Client, KongIngressClass)
if err != nil {
Expand All @@ -65,7 +65,7 @@ func (r *resourceReader) readResourcesFromCluster(ctx context.Context) (*storage
}

func (r *resourceReader) readResourcesFromFile(filename string) (*storage, error) {
st := newStorage()
st := newResourceStorage()

ingresses, err := common.ReadIngressesFromFile(filename, r.conf.Namespace, KongIngressClass)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/i2gw/providers/kong/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type storage struct {
TCPIngresses []kongv1beta1.TCPIngress
}

func newStorage() *storage {
func newResourceStorage() *storage {
return &storage{
Ingresses: map[types.NamespacedName]*networkingv1.Ingress{},
TCPIngresses: []kongv1beta1.TCPIngress{},
Expand Down

0 comments on commit 72cfb9e

Please sign in to comment.