@@ -27,24 +27,28 @@ import (
27
27
"k8s.io/apimachinery/pkg/runtime/schema"
28
28
"k8s.io/apimachinery/pkg/types"
29
29
"k8s.io/apimachinery/pkg/util/validation/field"
30
+ "sigs.k8s.io/controller-runtime/pkg/client"
30
31
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
31
32
)
32
33
33
34
// ToGateway converts the received ingresses to i2gw.GatewayResources,
34
35
// without taking into consideration any provider specific logic.
35
36
//
36
- // If a provider wishes to recieve notifications from the common package,
37
+ // If a provider wishes to receive notifications from the common package,
37
38
// it can pass a notifications.NotificationCallback function which can be used
38
39
// 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.
40
41
func ToGateway (ingresses []networkingv1.Ingress , options i2gw.ProviderImplementationSpecificOptions , notifyOpts ... notifications.NotificationCallback ) (i2gw.GatewayResources , field.ErrorList ) {
41
42
aggregator := ingressAggregator {ruleGroups : map [ruleGroupKey ]* ingressRuleGroup {}}
42
43
43
44
var notify notifications.NotificationCallback
44
- if len (notifyOpts ) > 0 {
45
- notify = notifyOpts [0 ]
46
- } else {
45
+ switch len (notifyOpts ) {
46
+ case 0 :
47
47
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" )}
48
52
}
49
53
50
54
var errs field.ErrorList
@@ -183,6 +187,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
183
187
var httpRoutes []gatewayv1.HTTPRoute
184
188
var errors field.ErrorList
185
189
listenersByNamespacedGateway := map [string ][]gatewayv1.Listener {}
190
+ ingressByNamespacedGateway := map [string ][]client.Object {}
186
191
187
192
for _ , rg := range a .ruleGroups {
188
193
listener := gatewayv1.Listener {}
@@ -200,6 +205,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
200
205
}
201
206
gwKey := fmt .Sprintf ("%s/%s" , rg .namespace , rg .ingressClass )
202
207
listenersByNamespacedGateway [gwKey ] = append (listenersByNamespacedGateway [gwKey ], listener )
208
+ ingressByNamespacedGateway [gwKey ] = append (ingressByNamespacedGateway [gwKey ], buildIngressFromRuleGroup (rg ))
203
209
httpRoute , errs := rg .toHTTPRoute (options , notify )
204
210
httpRoutes = append (httpRoutes , httpRoute )
205
211
errors = append (errors , errs ... )
@@ -235,7 +241,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
235
241
})
236
242
}
237
243
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 ))
239
245
httpRoutes = append (httpRoutes , httpRoute )
240
246
}
241
247
@@ -285,9 +291,9 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
285
291
}
286
292
287
293
var gateways []gatewayv1.Gateway
288
- for _ , gw := range gatewaysByKey {
294
+ for gwKey , gw := range gatewaysByKey {
289
295
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 ] ... )
291
297
}
292
298
293
299
return httpRoutes , gateways , errors
@@ -337,7 +343,7 @@ func (rg *ingressRuleGroup) toHTTPRoute(options i2gw.ProviderImplementationSpeci
337
343
httpRoute .Spec .Rules = append (httpRoute .Spec .Rules , hrRule )
338
344
}
339
345
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 ))
341
347
return httpRoute , errors
342
348
}
343
349
0 commit comments