-
Notifications
You must be signed in to change notification settings - Fork 48
/
gatewayclass.go
69 lines (58 loc) · 2.12 KB
/
gatewayclass.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package eventhandlers
import (
"context"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
gateway_api "sigs.k8s.io/gateway-api/apis/v1beta1"
"github.com/aws/aws-application-networking-k8s/pkg/config"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"
)
func NewEnqueueRequestsForGatewayClassEvent(log gwlog.Logger, client client.Client) handler.EventHandler {
return &enqueueRequestsForGatewayClassEvent{
log: log,
client: client,
}
}
type enqueueRequestsForGatewayClassEvent struct {
log gwlog.Logger
client client.Client
}
func (h *enqueueRequestsForGatewayClassEvent) Create(ctx context.Context, e event.CreateEvent, queue workqueue.RateLimitingInterface) {
gwClassNew := e.Object.(*gateway_api.GatewayClass)
h.enqueueImpactedGateway(ctx, queue, gwClassNew)
}
func (h *enqueueRequestsForGatewayClassEvent) Update(ctx context.Context, e event.UpdateEvent, queue workqueue.RateLimitingInterface) {
}
func (h *enqueueRequestsForGatewayClassEvent) Delete(ctx context.Context, e event.DeleteEvent, queue workqueue.RateLimitingInterface) {
}
func (h *enqueueRequestsForGatewayClassEvent) Generic(ctx context.Context, e event.GenericEvent, queue workqueue.RateLimitingInterface) {
}
func (h *enqueueRequestsForGatewayClassEvent) enqueueImpactedGateway(
ctx context.Context,
queue workqueue.RateLimitingInterface,
gwClass *gateway_api.GatewayClass,
) {
gwList := &gateway_api.GatewayList{}
err := h.client.List(ctx, gwList)
if err != nil {
h.log.Errorf("Error listing Gateways during GatewayClass event %s", err)
return
}
for _, gw := range gwList.Items {
if string(gw.Spec.GatewayClassName) == gwClass.Name {
if gwClass.Spec.ControllerName == config.LatticeGatewayControllerName {
h.log.Debugf("Found matching gateway, %s-%s", gw.Name, gw.Namespace)
queue.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: gw.Namespace,
Name: gw.Name,
},
})
}
}
}
}