@@ -21,6 +21,7 @@ import (
21
21
"strings"
22
22
23
23
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
24
+ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications"
24
25
networkingv1 "k8s.io/api/networking/v1"
25
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
27
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -31,9 +32,21 @@ import (
31
32
32
33
// ToGateway converts the received ingresses to i2gw.GatewayResources,
33
34
// without taking into consideration any provider specific logic.
34
- func ToGateway (ingresses []networkingv1.Ingress , options i2gw.ProviderImplementationSpecificOptions ) (i2gw.GatewayResources , field.ErrorList ) {
35
+ //
36
+ // If a provider wishes to recieve notifications from the common package,
37
+ // it can pass a notifications.NotificationCallback function which can be used
38
+ // to send notifications on behalf of the provider while keeping the logic of
39
+ // ToGateway seperated from the provider.
40
+ func ToGateway (ingresses []networkingv1.Ingress , options i2gw.ProviderImplementationSpecificOptions , notifyOpts ... notifications.NotificationCallback ) (i2gw.GatewayResources , field.ErrorList ) {
35
41
aggregator := ingressAggregator {ruleGroups : map [ruleGroupKey ]* ingressRuleGroup {}}
36
42
43
+ var notify notifications.NotificationCallback
44
+ if len (notifyOpts ) > 0 {
45
+ notify = notifyOpts [0 ]
46
+ } else {
47
+ notify = noNotifications
48
+ }
49
+
37
50
var errs field.ErrorList
38
51
for _ , ingress := range ingresses {
39
52
aggregator .addIngress (ingress )
@@ -42,7 +55,7 @@ func ToGateway(ingresses []networkingv1.Ingress, options i2gw.ProviderImplementa
42
55
return i2gw.GatewayResources {}, errs
43
56
}
44
57
45
- routes , gateways , errs := aggregator .toHTTPRoutesAndGateways (options )
58
+ routes , gateways , errs := aggregator .toHTTPRoutesAndGateways (options , notify )
46
59
if len (errs ) > 0 {
47
60
return i2gw.GatewayResources {}, errs
48
61
}
@@ -166,7 +179,7 @@ func (a *ingressAggregator) addIngressRule(namespace, name, ingressClass string,
166
179
rg .rules = append (rg .rules , ingressRule {rule : rule })
167
180
}
168
181
169
- func (a * ingressAggregator ) toHTTPRoutesAndGateways (options i2gw.ProviderImplementationSpecificOptions ) ([]gatewayv1.HTTPRoute , []gatewayv1.Gateway , field.ErrorList ) {
182
+ func (a * ingressAggregator ) toHTTPRoutesAndGateways (options i2gw.ProviderImplementationSpecificOptions , notify notifications. NotificationCallback ) ([]gatewayv1.HTTPRoute , []gatewayv1.Gateway , field.ErrorList ) {
170
183
var httpRoutes []gatewayv1.HTTPRoute
171
184
var errors field.ErrorList
172
185
listenersByNamespacedGateway := map [string ][]gatewayv1.Listener {}
@@ -187,7 +200,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
187
200
}
188
201
gwKey := fmt .Sprintf ("%s/%s" , rg .namespace , rg .ingressClass )
189
202
listenersByNamespacedGateway [gwKey ] = append (listenersByNamespacedGateway [gwKey ], listener )
190
- httpRoute , errs := rg .toHTTPRoute (options )
203
+ httpRoute , errs := rg .toHTTPRoute (options , notify )
191
204
httpRoutes = append (httpRoutes , httpRoute )
192
205
errors = append (errors , errs ... )
193
206
}
@@ -222,6 +235,7 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
222
235
})
223
236
}
224
237
238
+ notify (notifications .InfoNotification , fmt .Sprintf ("successfully converted to HTTPRoute \" %v/%v\" " , httpRoute .Namespace , httpRoute .Name ), mockIngressFromDefaultBackend (db ))
225
239
httpRoutes = append (httpRoutes , httpRoute )
226
240
}
227
241
@@ -273,12 +287,13 @@ func (a *ingressAggregator) toHTTPRoutesAndGateways(options i2gw.ProviderImpleme
273
287
var gateways []gatewayv1.Gateway
274
288
for _ , gw := range gatewaysByKey {
275
289
gateways = append (gateways , * gw )
290
+ notify (notifications .InfoNotification , fmt .Sprintf ("successfully created Gateway \" %v/%v\" " , gw .Namespace , gw .Name ))
276
291
}
277
292
278
293
return httpRoutes , gateways , errors
279
294
}
280
295
281
- func (rg * ingressRuleGroup ) toHTTPRoute (options i2gw.ProviderImplementationSpecificOptions ) (gatewayv1.HTTPRoute , field.ErrorList ) {
296
+ func (rg * ingressRuleGroup ) toHTTPRoute (options i2gw.ProviderImplementationSpecificOptions , notify notifications. NotificationCallback ) (gatewayv1.HTTPRoute , field.ErrorList ) {
282
297
ingressPathsByMatchKey := groupIngressPathsByMatchKey (rg .rules )
283
298
httpRoute := gatewayv1.HTTPRoute {
284
299
ObjectMeta : metav1.ObjectMeta {
@@ -322,6 +337,7 @@ func (rg *ingressRuleGroup) toHTTPRoute(options i2gw.ProviderImplementationSpeci
322
337
httpRoute .Spec .Rules = append (httpRoute .Spec .Rules , hrRule )
323
338
}
324
339
340
+ notify (notifications .InfoNotification , fmt .Sprintf ("successfully converted to HTTPRoute \" %v/%v\" " , httpRoute .Namespace , httpRoute .Name ), mockIngressFromRuleGroup (rg ))
325
341
return httpRoute , errors
326
342
}
327
343
0 commit comments