@@ -27,24 +27,28 @@ import (
2727 "k8s.io/apimachinery/pkg/runtime/schema"
2828 "k8s.io/apimachinery/pkg/types"
2929 "k8s.io/apimachinery/pkg/util/validation/field"
30+ "sigs.k8s.io/controller-runtime/pkg/client"
3031 gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3132)
3233
3334// ToGateway converts the received ingresses to i2gw.GatewayResources,
3435// without taking into consideration any provider specific logic.
3536//
36- // If a provider wishes to recieve notifications from the common package,
37+ // If a provider wishes to receive notifications from the common package,
3738// it can pass a notifications.NotificationCallback function which can be used
3839// to send notifications on behalf of the provider while keeping the logic of
39- // ToGateway seperated from the provider.
40+ // ToGateway separated from the provider.
4041func ToGateway (ingresses []networkingv1.Ingress , options i2gw.ProviderImplementationSpecificOptions , notifyOpts ... notifications.NotificationCallback ) (i2gw.GatewayResources , field.ErrorList ) {
4142 aggregator := ingressAggregator {ruleGroups : map [ruleGroupKey ]* ingressRuleGroup {}}
4243
4344 var notify notifications.NotificationCallback
44- if len (notifyOpts ) > 0 {
45- notify = notifyOpts [0 ]
46- } else {
45+ switch len (notifyOpts ) {
46+ case 0 :
4747 notify = noNotifications
48+ case 1 :
49+ notify = notifyOpts [0 ]
50+ default :
51+ return i2gw.GatewayResources {}, field.ErrorList {field .Invalid (field .NewPath ("" ), "" , "number of notification callbacks exceeded. only 0 or 1 callbacks are currently supported" )}
4852 }
4953
5054 var errs field.ErrorList
@@ -183,6 +187,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
183187 var httpRoutes []gatewayv1.HTTPRoute
184188 var errors field.ErrorList
185189 listenersByNamespacedGateway := map [string ][]gatewayv1.Listener {}
190+ ingressByNamespacedGateway := map [string ][]client.Object {}
186191
187192 for _ , rg := range a .ruleGroups {
188193 listener := gatewayv1.Listener {}
@@ -200,6 +205,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
200205 }
201206 gwKey := fmt .Sprintf ("%s/%s" , rg .namespace , rg .ingressClass )
202207 listenersByNamespacedGateway [gwKey ] = append (listenersByNamespacedGateway [gwKey ], listener )
208+ ingressByNamespacedGateway [gwKey ] = append (ingressByNamespacedGateway [gwKey ], buildIngressFromRuleGroup (rg ))
203209 httpRoute , errs := rg .toHTTPRoute (options , notify )
204210 httpRoutes = append (httpRoutes , httpRoute )
205211 errors = append (errors , errs ... )
@@ -235,7 +241,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
235241 })
236242 }
237243
238- notify (notifications .InfoNotification , fmt .Sprintf ("successfully converted to HTTPRoute \" %v/%v\" " , httpRoute .Namespace , httpRoute .Name ), mockIngressFromDefaultBackend (db ))
244+ notify (notifications .InfoNotification , fmt .Sprintf ("successfully converted to HTTPRoute \" %v/%v\" " , httpRoute .Namespace , httpRoute .Name ), buildIngressFromDefaultBackend (db ))
239245 httpRoutes = append (httpRoutes , httpRoute )
240246 }
241247
@@ -285,9 +291,9 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
285291 }
286292
287293 var gateways []gatewayv1.Gateway
288- for _ , gw := range gatewaysByKey {
294+ for gwKey , gw := range gatewaysByKey {
289295 gateways = append (gateways , * gw )
290- notify (notifications .InfoNotification , fmt .Sprintf ("successfully created Gateway \" %v/%v\" " , gw .Namespace , gw .Name ))
296+ notify (notifications .InfoNotification , fmt .Sprintf ("successfully created Gateway \" %v/%v\" " , gw .Namespace , gw .Name ), ingressByNamespacedGateway [ gwKey ] ... )
291297 }
292298
293299 return httpRoutes , gateways , errors
@@ -337,7 +343,7 @@ func (rg *ingressRuleGroup) toHTTPRoute(options i2gw.ProviderImplementationSpeci
337343 httpRoute .Spec .Rules = append (httpRoute .Spec .Rules , hrRule )
338344 }
339345
340- notify (notifications .InfoNotification , fmt .Sprintf ("successfully converted to HTTPRoute \" %v/%v\" " , httpRoute .Namespace , httpRoute .Name ), mockIngressFromRuleGroup (rg ))
346+ notify (notifications .InfoNotification , fmt .Sprintf ("successfully converted to HTTPRoute \" %v/%v\" " , httpRoute .Namespace , httpRoute .Name ), buildIngressFromRuleGroup (rg ))
341347 return httpRoute , errors
342348}
343349
0 commit comments