Skip to content

Commit

Permalink
Do not trigger DAG rebuild for irrelevant HTTProutes/TLSroutes (proje…
Browse files Browse the repository at this point in the history
…ctcontour#4912)

For HTTProute/TLSRoute, only if it references the relevant Gateway, it
will trigger DAG rebuild.

Signed-off-by: Fang Peng <fpeng@vmware.com>
  • Loading branch information
fangfpeng committed Dec 16, 2022
1 parent 0591fc2 commit a81e387
Show file tree
Hide file tree
Showing 3 changed files with 323 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/4912-fangfpeng-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't trigger DAG rebuilds/xDS configuration updates for irrelevant HTTPRoutes and TLSRoutes.
26 changes: 20 additions & 6 deletions internal/dag/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/gatewayapi"
"github.com/projectcontour/contour/internal/ingressclass"
"github.com/projectcontour/contour/internal/k8s"
"github.com/projectcontour/contour/internal/ref"
Expand Down Expand Up @@ -186,10 +187,10 @@ func (kc *KubernetesCache) Insert(obj interface{}) bool {
}
case *gatewayapi_v1beta1.HTTPRoute:
kc.httproutes[k8s.NamespacedNameOf(obj)] = obj
return true
return kc.routeTriggersRebuild(obj.Spec.ParentRefs)
case *gatewayapi_v1alpha2.TLSRoute:
kc.tlsroutes[k8s.NamespacedNameOf(obj)] = obj
return true
return kc.routeTriggersRebuild(obj.Spec.ParentRefs)
case *gatewayapi_v1beta1.ReferenceGrant:
kc.referencegrants[k8s.NamespacedNameOf(obj)] = obj
return true
Expand Down Expand Up @@ -304,14 +305,12 @@ func (kc *KubernetesCache) remove(obj interface{}) bool {
}
case *gatewayapi_v1beta1.HTTPRoute:
m := k8s.NamespacedNameOf(obj)
_, ok := kc.httproutes[m]
delete(kc.httproutes, m)
return ok
return kc.routeTriggersRebuild(obj.Spec.ParentRefs)
case *gatewayapi_v1alpha2.TLSRoute:
m := k8s.NamespacedNameOf(obj)
_, ok := kc.tlsroutes[m]
delete(kc.tlsroutes, m)
return ok
return kc.routeTriggersRebuild(obj.Spec.ParentRefs)
case *gatewayapi_v1beta1.ReferenceGrant:
m := k8s.NamespacedNameOf(obj)
_, ok := kc.referencegrants[m]
Expand Down Expand Up @@ -514,6 +513,21 @@ func isRefToSecret(ref gatewayapi_v1beta1.SecretObjectReference, secret *v1.Secr
string(ref.Name) == secret.Name
}

// routesTriggersRebuild returns true if this route references gateway in this cache.
func (kc *KubernetesCache) routeTriggersRebuild(parentRefs []gatewayapi_v1beta1.ParentReference) bool {
if kc.gateway == nil {
return false
}

for _, parentRef := range parentRefs {
if gatewayapi.IsRefToGateway(parentRef, k8s.NamespacedNameOf(kc.gateway)) {
return true
}
}

return false
}

func (kc *KubernetesCache) LookupTLSSecret(name types.NamespacedName) (*Secret, error) {
sec, ok := kc.secrets[name]
if !ok {
Expand Down

0 comments on commit a81e387

Please sign in to comment.