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
8 changes: 5 additions & 3 deletions pkg/i2gw/providers/common/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type pathMatchKey string

type ingressRuleGroup struct {
namespace string
name string
ingressClass string
host string
tls []networkingv1.IngressTLS
Expand Down Expand Up @@ -125,7 +126,7 @@ func (a *ingressAggregator) addIngress(ingress networkingv1.Ingress) field.Error
ingressClass = ingress.Name
}
for _, rule := range ingress.Spec.Rules {
a.addIngressRule(ingress.Namespace, ingressClass, rule, ingress.Spec)
a.addIngressRule(ingress.Namespace, ingress.Name, ingressClass, rule, ingress.Spec)
}
if ingress.Spec.DefaultBackend != nil {
a.defaultBackends = append(a.defaultBackends, ingressDefaultBackend{
Expand All @@ -138,12 +139,13 @@ func (a *ingressAggregator) addIngress(ingress networkingv1.Ingress) field.Error
return nil
}

func (a *ingressAggregator) addIngressRule(namespace, ingressClass string, rule networkingv1.IngressRule, iSpec networkingv1.IngressSpec) {
func (a *ingressAggregator) addIngressRule(namespace, name, ingressClass string, rule networkingv1.IngressRule, iSpec networkingv1.IngressSpec) {
rgKey := ruleGroupKey(fmt.Sprintf("%s/%s/%s", namespace, ingressClass, rule.Host))
rg, ok := a.ruleGroups[rgKey]
if !ok {
rg = &ingressRuleGroup{
namespace: namespace,
name: name,
ingressClass: ingressClass,
host: rule.Host,
}
Expand Down Expand Up @@ -281,7 +283,7 @@ func (rg *ingressRuleGroup) toHTTPRoute() (gatewayv1beta1.HTTPRoute, field.Error

httpRoute := gatewayv1beta1.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: NameFromHost(rg.host),
Name: RouteName(rg.name, rg.host),
Namespace: rg.namespace,
},
Spec: gatewayv1beta1.HTTPRouteSpec{},
Expand Down
32 changes: 16 additions & 16 deletions pkg/i2gw/providers/common/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Test_ingresses2GatewaysAndHttpRoutes(t *testing.T) {
{
name: "simple ingress",
ingresses: []networkingv1.Ingress{{
ObjectMeta: metav1.ObjectMeta{Name: "example", Namespace: "test"},
ObjectMeta: metav1.ObjectMeta{Name: "simple", Namespace: "test"},
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{{
Host: "example.com",
Expand All @@ -77,10 +77,10 @@ func Test_ingresses2GatewaysAndHttpRoutes(t *testing.T) {
}},
expectedGatewayResources: i2gw.GatewayResources{
Gateways: map[types.NamespacedName]gatewayv1beta1.Gateway{
{Namespace: "test", Name: "example"}: {
ObjectMeta: metav1.ObjectMeta{Name: "example", Namespace: "test"},
{Namespace: "test", Name: "simple"}: {
ObjectMeta: metav1.ObjectMeta{Name: "simple", Namespace: "test"},
Spec: gatewayv1beta1.GatewaySpec{
GatewayClassName: "example",
GatewayClassName: "simple",
Listeners: []gatewayv1beta1.Listener{{
Name: "example-com-http",
Port: 80,
Expand All @@ -91,12 +91,12 @@ func Test_ingresses2GatewaysAndHttpRoutes(t *testing.T) {
},
},
HTTPRoutes: map[types.NamespacedName]gatewayv1beta1.HTTPRoute{
{Namespace: "test", Name: "example-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "example-com", Namespace: "test"},
{Namespace: "test", Name: "simple-example-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "simple-example-com", Namespace: "test"},
Spec: gatewayv1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
ParentRefs: []gatewayv1beta1.ParentReference{{
Name: "example",
Name: "simple",
}},
},
Hostnames: []gatewayv1beta1.Hostname{"example.com"},
Expand Down Expand Up @@ -125,7 +125,7 @@ func Test_ingresses2GatewaysAndHttpRoutes(t *testing.T) {
{
name: "ingress with TLS",
ingresses: []networkingv1.Ingress{{
ObjectMeta: metav1.ObjectMeta{Name: "example", Namespace: "test"},
ObjectMeta: metav1.ObjectMeta{Name: "with-tls", Namespace: "test"},
Spec: networkingv1.IngressSpec{
TLS: []networkingv1.IngressTLS{{
Hosts: []string{"example.com"},
Expand Down Expand Up @@ -154,10 +154,10 @@ func Test_ingresses2GatewaysAndHttpRoutes(t *testing.T) {
}},
expectedGatewayResources: i2gw.GatewayResources{
Gateways: map[types.NamespacedName]gatewayv1beta1.Gateway{
{Namespace: "test", Name: "example"}: {
ObjectMeta: metav1.ObjectMeta{Name: "example", Namespace: "test"},
{Namespace: "test", Name: "with-tls"}: {
ObjectMeta: metav1.ObjectMeta{Name: "with-tls", Namespace: "test"},
Spec: gatewayv1beta1.GatewaySpec{
GatewayClassName: "example",
GatewayClassName: "with-tls",
Listeners: []gatewayv1beta1.Listener{{
Name: "example-com-http",
Port: 80,
Expand All @@ -178,12 +178,12 @@ func Test_ingresses2GatewaysAndHttpRoutes(t *testing.T) {
},
},
HTTPRoutes: map[types.NamespacedName]gatewayv1beta1.HTTPRoute{
{Namespace: "test", Name: "example-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "example-com", Namespace: "test"},
{Namespace: "test", Name: "with-tls-example-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "with-tls-example-com", Namespace: "test"},
Spec: gatewayv1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
ParentRefs: []gatewayv1beta1.ParentReference{{
Name: "example",
Name: "with-tls",
}},
},
Hostnames: []gatewayv1beta1.Hostname{"example.com"},
Expand Down Expand Up @@ -259,8 +259,8 @@ func Test_ingresses2GatewaysAndHttpRoutes(t *testing.T) {
},
},
HTTPRoutes: map[types.NamespacedName]gatewayv1beta1.HTTPRoute{
{Namespace: "different", Name: "example-net"}: {
ObjectMeta: metav1.ObjectMeta{Name: "example-net", Namespace: "different"},
{Namespace: "different", Name: "net-example-net"}: {
ObjectMeta: metav1.ObjectMeta{Name: "net-example-net", Namespace: "different"},
Spec: gatewayv1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
ParentRefs: []gatewayv1beta1.ParentReference{{
Expand Down
6 changes: 6 additions & 0 deletions pkg/i2gw/providers/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func GetIngressClass(ingress networkingv1.Ingress) string {

type IngressRuleGroup struct {
Namespace string
Name string
IngressClass string
Host string
TLS []networkingv1.IngressTLS
Expand All @@ -66,6 +67,7 @@ func GetRuleGroups(ingresses []networkingv1.Ingress) map[string]IngressRuleGroup
if !ok {
rg = IngressRuleGroup{
Namespace: ingress.Namespace,
Name: ingress.Name,
IngressClass: ingressClass,
Host: rule.Host,
}
Expand Down Expand Up @@ -99,6 +101,10 @@ func NameFromHost(host string) string {
return step2
}

func RouteName(ingressName, host string) string {
return fmt.Sprintf("%s-%s", ingressName, NameFromHost(host))
}

func ToBackendRef(ib networkingv1.IngressBackend, path *field.Path) (*gatewayv1beta1.BackendRef, *field.Error) {
if ib.Service != nil {
if ib.Service.Port.Name != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/i2gw/providers/ingressnginx/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func canaryFeature(ingressResources i2gw.InputResources, gatewayResources *i2gw.
backendRefs, calculationErrs := calculateBackendRefWeight(paths)
errs = append(errs, calculationErrs...)

key := types.NamespacedName{Namespace: path.ingress.Namespace, Name: common.NameFromHost(rg.Host)}
key := types.NamespacedName{Namespace: path.ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
httpRoute, ok := gatewayResources.HTTPRoutes[key]
if !ok {
panic("HTTPRoute not exists - this should never happen")
Expand Down
4 changes: 2 additions & 2 deletions pkg/i2gw/providers/ingressnginx/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func Test_ToGateway(t *testing.T) {
},
},
HTTPRoutes: map[types.NamespacedName]gatewayv1beta1.HTTPRoute{
{Namespace: "default", Name: "echo-prod-mydomain-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "echo-prod-mydomain-com", Namespace: "default"},
{Namespace: "default", Name: "production-echo-prod-mydomain-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "production-echo-prod-mydomain-com", Namespace: "default"},
Spec: gatewayv1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
ParentRefs: []gatewayv1beta1.ParentReference{{
Expand Down
8 changes: 4 additions & 4 deletions pkg/i2gw/providers/kong/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func Test_ToGateway(t *testing.T) {
},
},
HTTPRoutes: map[types.NamespacedName]gatewayv1beta1.HTTPRoute{
{Namespace: "default", Name: "test-mydomain-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "test-mydomain-com", Namespace: "default"},
{Namespace: "default", Name: "multiple-matching-single-rule-test-mydomain-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "multiple-matching-single-rule-test-mydomain-com", Namespace: "default"},
Spec: gatewayv1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
ParentRefs: []gatewayv1beta1.ParentReference{{
Expand Down Expand Up @@ -225,8 +225,8 @@ func Test_ToGateway(t *testing.T) {
},
},
HTTPRoutes: map[types.NamespacedName]gatewayv1beta1.HTTPRoute{
{Namespace: "default", Name: "test-mydomain-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "test-mydomain-com", Namespace: "default"},
{Namespace: "default", Name: "multiple-matching-multiple-rules-test-mydomain-com"}: {
ObjectMeta: metav1.ObjectMeta{Name: "multiple-matching-multiple-rules-test-mydomain-com", Namespace: "default"},
Spec: gatewayv1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1beta1.CommonRouteSpec{
ParentRefs: []gatewayv1beta1.ParentReference{{
Expand Down
2 changes: 1 addition & 1 deletion pkg/i2gw/providers/kong/header_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func headerMatchingFeature(ingressResources i2gw.InputResources, gatewayResource
for _, rg := range ruleGroups {
for _, rule := range rg.Rules {
headerskeys, headersValues := parseHeadersAnnotations(rule.Ingress.Annotations)
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.NameFromHost(rg.Host)}
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
httpRoute, ok := gatewayResources.HTTPRoutes[key]
if !ok {
panic("HTTPRoute does not exist - this should never happen")
Expand Down
4 changes: 2 additions & 2 deletions pkg/i2gw/providers/kong/header_matching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestHeaderMatchingFeature(t *testing.T) {
},
},
expectedHTTPRouteMatches: map[string][][]gatewayv1beta1.HTTPRouteMatch{
"default/test-mydomain-com": {
"default/ored-headers-test-mydomain-com": {
{
gatewayv1beta1.HTTPRouteMatch{
Headers: []gatewayv1beta1.HTTPHeaderMatch{
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestHeaderMatchingFeature(t *testing.T) {
},
},
expectedHTTPRouteMatches: map[string][][]gatewayv1beta1.HTTPRouteMatch{
"default/test-mydomain-com": {
"default/anded-ored-headers-test-mydomain-com": {
{
gatewayv1beta1.HTTPRouteMatch{
Headers: []gatewayv1beta1.HTTPHeaderMatch{
Expand Down
2 changes: 1 addition & 1 deletion pkg/i2gw/providers/kong/method_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func methodMatchingFeature(ingressResources i2gw.InputResources, gatewayResource
ruleGroups := common.GetRuleGroups(ingressResources.Ingresses)
for _, rg := range ruleGroups {
for _, rule := range rg.Rules {
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.NameFromHost(rg.Host)}
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
httpRoute, ok := gatewayResources.HTTPRoutes[key]
if !ok {
panic("HTTPRoute does not exist - this should never happen")
Expand Down
6 changes: 3 additions & 3 deletions pkg/i2gw/providers/kong/method_matching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestMethodMatchingFeature(t *testing.T) {
},
},
expectedHTTPRouteMatches: map[string][][]gatewayv1beta1.HTTPRouteMatch{
"default/test-mydomain-com": {
"default/one-method-test-mydomain-com": {
{
gatewayv1beta1.HTTPRouteMatch{
Method: ptrTo(gatewayv1beta1.HTTPMethodGet),
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestMethodMatchingFeature(t *testing.T) {
},
},
expectedHTTPRouteMatches: map[string][][]gatewayv1beta1.HTTPRouteMatch{
"default/test-mydomain-com": {
"default/many-methods-test-mydomain-com": {
{
gatewayv1beta1.HTTPRouteMatch{
Method: ptrTo(gatewayv1beta1.HTTPMethodGet),
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestMethodMatchingFeature(t *testing.T) {
},
expectedErrors: field.ErrorList{
field.Invalid(
field.NewPath("default/wrong-method").Child("metadata").Child("annotations"),
field.NewPath("default/wrong-method-wrong-method").Child("metadata").Child("annotations"),
"WRONG",
"method not supported",
),
Expand Down
2 changes: 1 addition & 1 deletion pkg/i2gw/providers/kong/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func pluginsFeature(ingressResources i2gw.InputResources, gatewayResources *i2gw
ruleGroups := common.GetRuleGroups(ingressResources.Ingresses)
for _, rg := range ruleGroups {
for _, rule := range rg.Rules {
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.NameFromHost(rg.Host)}
key := types.NamespacedName{Namespace: rule.Ingress.Namespace, Name: common.RouteName(rg.Name, rg.Host)}
httpRoute, ok := gatewayResources.HTTPRoutes[key]
if !ok {
panic("HTTPRoute does not exist - this should never happen")
Expand Down