Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicated xroutes are added to gatewayapi.Resources #3282

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ func newGatewayAPIController(mgr manager.Manager, cfg *config.Server, su Updater
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{}
Comment on lines 118 to +128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace this with sets.set[string]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracked with #3411

// 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 @@ -127,6 +137,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 @@ -43,6 +43,12 @@
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

Check warning on line 49 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L48-L49

Added lines #L48 - L49 were not covered by tests
}

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

for _, rule := range tlsRoute.Spec.Rules {
Expand Down Expand Up @@ -82,6 +88,7 @@
}

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 @@ -115,6 +122,12 @@
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

Check warning on line 128 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L127-L128

Added lines #L127 - L128 were not covered by tests
}

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

for _, rule := range grpcRoute.Spec.Rules {
Expand Down Expand Up @@ -193,6 +206,7 @@
}

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 = gwapiv1.GRPCRouteStatus{}
Expand Down Expand Up @@ -235,6 +249,12 @@
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

Check warning on line 255 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L254-L255

Added lines #L254 - L255 were not covered by tests
}

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

for _, rule := range httpRoute.Spec.Rules {
Expand Down Expand Up @@ -367,6 +387,7 @@
}

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 @@ -399,6 +420,12 @@
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

Check warning on line 426 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L425-L426

Added lines #L425 - L426 were not covered by tests
}

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

for _, rule := range tcpRoute.Spec.Rules {
Expand Down Expand Up @@ -438,6 +465,7 @@
}

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 @@ -470,6 +498,12 @@
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

Check warning on line 504 in internal/provider/kubernetes/routes.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/routes.go#L503-L504

Added lines #L503 - L504 were not covered by tests
}

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

for _, rule := range udpRoute.Spec.Rules {
Expand Down Expand Up @@ -509,6 +543,7 @@
}

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