diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index 39ed94e8749..58fa5f085d7 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -795,31 +795,53 @@ func (r *gatewayAPIReconciler) processEnvoyProxies(ctx context.Context, managedG // processEnvoyProxyObjectRefs adds the referenced resources in EnvoyProxies // to the resourceTree // - BackendRefs for AccessLog +// - BackendRefs for Metrics +// - BackendRefs for Tracing func (r *gatewayAPIReconciler) processEnvoyProxyObjectRefs(resourceTree *gatewayapi.Resources, resourceMap *resourceMappings) { if resourceTree.EnvoyProxy == nil { return } envoyproxy := resourceTree.EnvoyProxy - if envoyproxy.Spec.Telemetry != nil && envoyproxy.Spec.Telemetry.AccessLog != nil { + if envoyproxy.Spec.Telemetry != nil { + backendRefs := []egv1a1.BackendRef{} - // Add the referenced BackendRefs in AccessLog to Maps for later processing - accessLog := envoyproxy.Spec.Telemetry.AccessLog - for _, settings := range accessLog.Settings { - for _, sink := range settings.Sinks { - if sink.OpenTelemetry != nil { - for _, backendRef := range sink.OpenTelemetry.BackendRefs { - backendNamespace := gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ - Group: backendRef.Group, - Kind: backendRef.Kind, - Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), - Name: backendRef.Name, - }] = struct{}{} + // Collect BackendRefs for access log sinks + if envoyproxy.Spec.Telemetry.AccessLog != nil { + for _, settings := range envoyproxy.Spec.Telemetry.AccessLog.Settings { + for _, sink := range settings.Sinks { + if sink.OpenTelemetry != nil { + backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...) } } } } + + // Collect BackendRefs for metrics sinks + if envoyproxy.Spec.Telemetry.Metrics != nil { + for _, sink := range envoyproxy.Spec.Telemetry.Metrics.Sinks { + if sink.OpenTelemetry != nil { + backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...) + } + } + + } + + // Collect BackendRefs for tracing provider + if envoyproxy.Spec.Telemetry.Tracing != nil { + backendRefs = append(backendRefs, envoyproxy.Spec.Telemetry.Tracing.Provider.BackendRefs...) + } + + // Append all referenced BackendRefs to maps + for _, backendRef := range backendRefs { + backendNamespace := gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace) + resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + Group: backendRef.Group, + Kind: backendRef.Kind, + Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), + Name: backendRef.Name, + }] = struct{}{} + } } } diff --git a/internal/provider/kubernetes/indexers.go b/internal/provider/kubernetes/indexers.go index e2afdf0a9ba..3e22eb5d441 100644 --- a/internal/provider/kubernetes/indexers.go +++ b/internal/provider/kubernetes/indexers.go @@ -65,30 +65,53 @@ func addEnvoyProxyIndexers(ctx context.Context, mgr manager.Manager) error { func backendEnvoyProxyIndexFunc(rawObj client.Object) []string { envoyproxy := rawObj.(*v1alpha1.EnvoyProxy) - var backendRefs []string + var backendIndex []string - if envoyproxy.Spec.Telemetry != nil && envoyproxy.Spec.Telemetry.AccessLog != nil { - for _, settings := range envoyproxy.Spec.Telemetry.AccessLog.Settings { - for _, sink := range settings.Sinks { - if sink.OpenTelemetry != nil { - for _, backendRef := range sink.OpenTelemetry.BackendRefs { - if backendRef.Kind == nil || string(*backendRef.Kind) == gatewayapi.KindService { - // If an explicit Backend namespace is not provided, use the EnvoyProxy namespace to - // lookup the provided Gateway Name. - backendRefs = append(backendRefs, - types.NamespacedName{ - Namespace: gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace), - Name: string(backendRef.Name), - }.String(), - ) - } + if envoyproxy.Spec.Telemetry != nil { + backendRefs := []v1alpha1.BackendRef{} + + // Collect BackendRefs for access log sinks + if envoyproxy.Spec.Telemetry.AccessLog != nil { + for _, settings := range envoyproxy.Spec.Telemetry.AccessLog.Settings { + for _, sink := range settings.Sinks { + if sink.OpenTelemetry != nil { + backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...) } } } } + + // Collect BackendRefs for metrics sinks + if envoyproxy.Spec.Telemetry.Metrics != nil { + for _, sink := range envoyproxy.Spec.Telemetry.Metrics.Sinks { + if sink.OpenTelemetry != nil { + backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...) + } + } + + } + + // Collect BackendRefs for tracing provider + if envoyproxy.Spec.Telemetry.Tracing != nil { + backendRefs = append(backendRefs, envoyproxy.Spec.Telemetry.Tracing.Provider.BackendRefs...) + } + + // Append all referenced BackendRefs to maps + for _, backendRef := range backendRefs { + if backendRef.Kind == nil || string(*backendRef.Kind) == gatewayapi.KindService { + // If an explicit Backend namespace is not provided, use the EnvoyProxy namespace to + // lookup the provided Gateway Name. + backendIndex = append(backendIndex, + types.NamespacedName{ + Namespace: gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace), + Name: string(backendRef.Name), + }.String(), + ) + } + } } - return backendRefs + return backendIndex } // addHTTPRouteIndexers adds indexing on HTTPRoute.