Skip to content

Commit

Permalink
add GenerationChanged predicate filter to all resources (#1993)
Browse files Browse the repository at this point in the history
* add GenerationChanged predicate filter to all resources

Signed-off-by: Karol Szwaj <[email protected]>

* add GenerationChanged predicate filter to all resources

Signed-off-by: Karol Szwaj <[email protected]>

* restore order to deployment predicate

Signed-off-by: Karol Szwaj <[email protected]>

* remove service and deployment predicate

Signed-off-by: Karol Szwaj <[email protected]>

---------

Signed-off-by: Karol Szwaj <[email protected]>
  • Loading branch information
cnvergence authored Oct 18, 2023
1 parent 54ce6fb commit c8f358b
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,13 +1270,15 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
if err := c.Watch(
source.Kind(mgr.GetCache(), &gwapiv1b1.GatewayClass{}),
handler.EnqueueRequestsFromMapFunc(r.enqueueClass),
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.hasMatchingController),
); err != nil {
return err
}

// Only enqueue EnvoyProxy objects that match this Envoy Gateway's GatewayClass.
epPredicates := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.ResourceVersionChangedPredicate{},
predicate.NewPredicateFuncs(r.hasManagedClass),
}
Expand All @@ -1292,7 +1294,10 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch Gateway CRUDs and reconcile affected GatewayClass.
gPredicates := []predicate.Predicate{predicate.NewPredicateFuncs(r.validateGatewayForReconcile)}
gPredicates := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.validateGatewayForReconcile),
}
if len(r.namespaceLabels) != 0 {
gPredicates = append(gPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1308,7 +1313,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch HTTPRoute CRUDs and process affected Gateways.
httprPredicates := []predicate.Predicate{}
httprPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
httprPredicates = append(httprPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1324,7 +1329,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch GRPCRoute CRUDs and process affected Gateways.
grpcrPredicates := []predicate.Predicate{}
grpcrPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
grpcrPredicates = append(grpcrPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1340,7 +1345,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch TLSRoute CRUDs and process affected Gateways.
tlsrPredicates := []predicate.Predicate{}
tlsrPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
tlsrPredicates = append(tlsrPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1356,7 +1361,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch UDPRoute CRUDs and process affected Gateways.
udprPredicates := []predicate.Predicate{}
udprPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
udprPredicates = append(udprPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1372,7 +1377,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch TCPRoute CRUDs and process affected Gateways.
tcprPredicates := []predicate.Predicate{}
tcprPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
tcprPredicates = append(tcprPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand Down Expand Up @@ -1410,14 +1415,18 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
if err := c.Watch(
source.Kind(mgr.GetCache(), &mcsapi.ServiceImport{}),
handler.EnqueueRequestsFromMapFunc(r.enqueueClass),
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.validateServiceImportForReconcile)); err != nil {
// ServiceImport is not available in the cluster, skip the watch and not throw error.
r.log.Info("unable to watch ServiceImport: %s", err.Error())
}
}

// Watch EndpointSlice CRUDs and process affected *Route objects.
esPredicates := []predicate.Predicate{predicate.NewPredicateFuncs(r.validateEndpointSliceForReconcile)}
esPredicates := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.validateEndpointSliceForReconcile),
}
if len(r.namespaceLabels) != 0 {
esPredicates = append(esPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1431,7 +1440,10 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M

// Watch Node CRUDs to update Gateway Address exposed by Service of type NodePort.
// Node creation/deletion and ExternalIP updates would require update in the Gateway
nPredicates := []predicate.Predicate{predicate.NewPredicateFuncs(r.handleNode)}
nPredicates := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.handleNode),
}
if len(r.namespaceLabels) != 0 {
nPredicates = append(nPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1445,7 +1457,10 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch Secret CRUDs and process affected Gateways.
secretPredicates := []predicate.Predicate{predicate.NewPredicateFuncs(r.validateSecretForReconcile)}
secretPredicates := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.validateSecretForReconcile),
}
if len(r.namespaceLabels) != 0 {
secretPredicates = append(secretPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1458,7 +1473,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch ReferenceGrant CRUDs and process affected Gateways.
rgPredicates := []predicate.Predicate{}
rgPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
rgPredicates = append(rgPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand Down Expand Up @@ -1487,7 +1502,10 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch AuthenticationFilter CRUDs and enqueue associated HTTPRoute objects.
afPredicates := []predicate.Predicate{predicate.NewPredicateFuncs(r.httpRoutesForAuthenticationFilter)}
afPredicates := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.httpRoutesForAuthenticationFilter),
}
if len(r.namespaceLabels) != 0 {
afPredicates = append(afPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1499,7 +1517,10 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
return err
}

rfPredicates := []predicate.Predicate{predicate.NewPredicateFuncs(r.httpRoutesForRateLimitFilter)}
rfPredicates := []predicate.Predicate{
predicate.GenerationChangedPredicate{},
predicate.NewPredicateFuncs(r.httpRoutesForRateLimitFilter),
}
if len(r.namespaceLabels) != 0 {
rfPredicates = append(rfPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1513,7 +1534,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch EnvoyPatchPolicy if enabled in config
eppPredicates := []predicate.Predicate{}
eppPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
eppPredicates = append(eppPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1529,7 +1550,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
}

// Watch ClientTrafficPolicy
ctpPredicates := []predicate.Predicate{}
ctpPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
ctpPredicates = append(ctpPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand All @@ -1545,7 +1566,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
r.log.Info("Watching gatewayAPI related objects")

// Watch any additional GVKs from the registered extension.
uPredicates := []predicate.Predicate{}
uPredicates := []predicate.Predicate{predicate.GenerationChangedPredicate{}}
if len(r.namespaceLabels) != 0 {
uPredicates = append(uPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels))
}
Expand Down

0 comments on commit c8f358b

Please sign in to comment.