Skip to content

Commit

Permalink
fix: duplicated xroutes are added to gatewayapi.Resources (envoyproxy…
Browse files Browse the repository at this point in the history
…#3282)

fix duplicated xroutes

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
(cherry picked from commit 32c6876)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
aoledk authored and arkodg committed Jun 8, 2024
1 parent 9ddca28 commit b4a3fe8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func newGatewayAPIController(mgr manager.Manager, cfg *config.Server, su status.
type resourceMappings struct {
// Map for storing namespaces for Route, Service and Gateway objects.
allAssociatedNamespaces map[string]struct{}
// Map for storing TLSRoutes' NamespacedNames attaching to various Gateway objects.
allAssociatedTLSRoutes map[string]struct{}
// Map for storing HTTPRoutes' NamespacedNames attaching to various Gateway objects.
allAssociatedHTTPRoutes map[string]struct{}
// Map for storing GRPCRoutes' NamespacedNames attaching to various Gateway objects.
allAssociatedGRPCRoutes map[string]struct{}
// Map for storing TCPRoutes' NamespacedNames attaching to various Gateway objects.
allAssociatedTCPRoutes map[string]struct{}
// Map for storing UDPRoutes' NamespacedNames attaching to various Gateway objects.
allAssociatedUDPRoutes map[string]struct{}
// Map for storing backendRefs' NamespaceNames referred by various Route objects.
allAssociatedBackendRefs map[gwapiv1.BackendObjectReference]struct{}
// extensionRefFilters is a map of filters managed by an extension.
Expand All @@ -125,6 +135,11 @@ type resourceMappings struct {
func newResourceMapping() *resourceMappings {
return &resourceMappings{
allAssociatedNamespaces: map[string]struct{}{},
allAssociatedTLSRoutes: map[string]struct{}{},
allAssociatedHTTPRoutes: map[string]struct{}{},
allAssociatedGRPCRoutes: map[string]struct{}{},
allAssociatedTCPRoutes: map[string]struct{}{},
allAssociatedUDPRoutes: map[string]struct{}{},
allAssociatedBackendRefs: map[gwapiv1.BackendObjectReference]struct{}{},
extensionRefFilters: map[types.NamespacedName]unstructured.Unstructured{},
}
Expand Down
35 changes: 35 additions & 0 deletions internal/provider/kubernetes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func (r *gatewayAPIReconciler) processTLSRoutes(ctx context.Context, gatewayName
continue
}
}

if _, ok := resourceMap.allAssociatedTLSRoutes[utils.NamespacedName(&tlsRoute).String()]; ok {
r.log.Info("current TLSRoute has been processed already", "namespace", tlsRoute.Namespace, "name", tlsRoute.Name)
continue
}

r.log.Info("processing TLSRoute", "namespace", tlsRoute.Namespace, "name", tlsRoute.Name)

for _, rule := range tlsRoute.Spec.Rules {
Expand Down Expand Up @@ -81,6 +87,7 @@ func (r *gatewayAPIReconciler) processTLSRoutes(ctx context.Context, gatewayName
}

resourceMap.allAssociatedNamespaces[tlsRoute.Namespace] = struct{}{}
resourceMap.allAssociatedTLSRoutes[utils.NamespacedName(&tlsRoute).String()] = struct{}{}
// Discard Status to reduce memory consumption in watchable
// It will be recomputed by the gateway-api layer
tlsRoute.Status = gwapiv1a2.TLSRouteStatus{}
Expand Down Expand Up @@ -113,6 +120,12 @@ func (r *gatewayAPIReconciler) processGRPCRoutes(ctx context.Context, gatewayNam
continue
}
}

if _, ok := resourceMap.allAssociatedGRPCRoutes[utils.NamespacedName(&grpcRoute).String()]; ok {
r.log.Info("current GRPCRoute has been processed already", "namespace", grpcRoute.Namespace, "name", grpcRoute.Name)
continue
}

r.log.Info("processing GRPCRoute", "namespace", grpcRoute.Namespace, "name", grpcRoute.Name)

for _, rule := range grpcRoute.Spec.Rules {
Expand Down Expand Up @@ -191,6 +204,7 @@ func (r *gatewayAPIReconciler) processGRPCRoutes(ctx context.Context, gatewayNam
}

resourceMap.allAssociatedNamespaces[grpcRoute.Namespace] = struct{}{}
resourceMap.allAssociatedGRPCRoutes[utils.NamespacedName(&grpcRoute).String()] = struct{}{}
// Discard Status to reduce memory consumption in watchable
// It will be recomputed by the gateway-api layer
grpcRoute.Status = gwapiv1a2.GRPCRouteStatus{}
Expand Down Expand Up @@ -232,6 +246,12 @@ func (r *gatewayAPIReconciler) processHTTPRoutes(ctx context.Context, gatewayNam
continue
}
}

if _, ok := resourceMap.allAssociatedHTTPRoutes[utils.NamespacedName(&httpRoute).String()]; ok {
r.log.Info("current HTTPRoute has been processed already", "namespace", httpRoute.Namespace, "name", httpRoute.Name)
continue
}

r.log.Info("processing HTTPRoute", "namespace", httpRoute.Namespace, "name", httpRoute.Name)

for _, rule := range httpRoute.Spec.Rules {
Expand Down Expand Up @@ -364,6 +384,7 @@ func (r *gatewayAPIReconciler) processHTTPRoutes(ctx context.Context, gatewayNam
}

resourceMap.allAssociatedNamespaces[httpRoute.Namespace] = struct{}{}
resourceMap.allAssociatedHTTPRoutes[utils.NamespacedName(&httpRoute).String()] = struct{}{}
// Discard Status to reduce memory consumption in watchable
// It will be recomputed by the gateway-api layer
httpRoute.Status = gwapiv1.HTTPRouteStatus{}
Expand Down Expand Up @@ -395,6 +416,12 @@ func (r *gatewayAPIReconciler) processTCPRoutes(ctx context.Context, gatewayName
continue
}
}

if _, ok := resourceMap.allAssociatedTCPRoutes[utils.NamespacedName(&tcpRoute).String()]; ok {
r.log.Info("current TCPRoute has been processed already", "namespace", tcpRoute.Namespace, "name", tcpRoute.Name)
continue
}

r.log.Info("processing TCPRoute", "namespace", tcpRoute.Namespace, "name", tcpRoute.Name)

for _, rule := range tcpRoute.Spec.Rules {
Expand Down Expand Up @@ -434,6 +461,7 @@ func (r *gatewayAPIReconciler) processTCPRoutes(ctx context.Context, gatewayName
}

resourceMap.allAssociatedNamespaces[tcpRoute.Namespace] = struct{}{}
resourceMap.allAssociatedTCPRoutes[utils.NamespacedName(&tcpRoute).String()] = struct{}{}
// Discard Status to reduce memory consumption in watchable
// It will be recomputed by the gateway-api layer
tcpRoute.Status = gwapiv1a2.TCPRouteStatus{}
Expand Down Expand Up @@ -465,6 +493,12 @@ func (r *gatewayAPIReconciler) processUDPRoutes(ctx context.Context, gatewayName
continue
}
}

if _, ok := resourceMap.allAssociatedUDPRoutes[utils.NamespacedName(&udpRoute).String()]; ok {
r.log.Info("current UDPRoute has been processed already", "namespace", udpRoute.Namespace, "name", udpRoute.Name)
continue
}

r.log.Info("processing UDPRoute", "namespace", udpRoute.Namespace, "name", udpRoute.Name)

for _, rule := range udpRoute.Spec.Rules {
Expand Down Expand Up @@ -504,6 +538,7 @@ func (r *gatewayAPIReconciler) processUDPRoutes(ctx context.Context, gatewayName
}

resourceMap.allAssociatedNamespaces[udpRoute.Namespace] = struct{}{}
resourceMap.allAssociatedUDPRoutes[utils.NamespacedName(&udpRoute).String()] = struct{}{}
// Discard Status to reduce memory consumption in watchable
// It will be recomputed by the gateway-api layer
udpRoute.Status = gwapiv1a2.UDPRouteStatus{}
Expand Down

0 comments on commit b4a3fe8

Please sign in to comment.