@@ -245,8 +245,78 @@ func TestCrossNamespaceReferences(t *testing.T) {
245245 // Monitor the cross-namespace endpoint
246246 manager .MonitorEndpointResources (ga , endpoints )
247247
248- // Verify no watches were created since cross-namespace references should be skipped
249- defaultManager , _ := manager .(* defaultEndpointResourcesManager )
250- resourceKey := ktypes.NamespacedName {Namespace : svcNamespace , Name : svcName }
251- assert .NotContains (t , defaultManager .serviceWatches , resourceKey , "Cross-namespace service watch should be skipped" )
248+ // Verify no watches were created since cross-namespace references should be skipped
249+ defaultManager , _ := manager .(* defaultEndpointResourcesManager )
250+ resourceKey := ktypes.NamespacedName {Namespace : svcNamespace , Name : svcName }
251+ assert .NotContains (t , defaultManager .serviceWatches , resourceKey , "Cross-namespace service watch should be skipped when not allowed" )
252+ })
253+
254+ t .Run ("cross-namespace reference allowed" , func (t * testing.T ) {
255+ // Create test dependencies
256+ clientSet := fake .NewSimpleClientset ()
257+ gwClient := fakegwclientset .NewSimpleClientset ()
258+
259+ // Use our mock event channels
260+ serviceEventChannel := NewMockEventChannel ()
261+ ingressEventChannel := NewMockEventChannel ()
262+ gatewayEventChannel := NewMockEventChannel ()
263+
264+ logger := logr .Discard ()
265+
266+ // Create the manager
267+ manager := NewEndpointResourcesManager (
268+ clientSet ,
269+ gwClient ,
270+ serviceEventChannel .Channel (),
271+ ingressEventChannel .Channel (),
272+ gatewayEventChannel .Channel (),
273+ logger ,
274+ )
275+
276+ // Create a GlobalAccelerator with cross-namespace endpoint
277+ ga := & agaapi.GlobalAccelerator {
278+ ObjectMeta : metav1.ObjectMeta {
279+ Name : "test-ga-allowed" ,
280+ Namespace : "default" ,
281+ },
282+ }
283+
284+ // Create loaded endpoint to a service in another namespace
285+ svcName := "cross-ns-service-allowed"
286+ svcNamespace := "other-namespace" // Different from GA's namespace
287+ endpoints := []* LoadedEndpoint {
288+ {
289+ Type : agaapi .GlobalAcceleratorEndpointTypeService ,
290+ Name : svcName ,
291+ Namespace : svcNamespace ,
292+ EndpointRef : & agaapi.GlobalAcceleratorEndpoint {
293+ Type : agaapi .GlobalAcceleratorEndpointTypeService ,
294+ Name : & svcName ,
295+ },
296+ Status : EndpointStatusLoaded ,
297+ ARN : "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/test-allowed" ,
298+ // Important: Set CrossNamespaceAllowed to true for this test
299+ CrossNamespaceAllowed : true ,
300+ },
301+ }
302+
303+ // Monitor the cross-namespace endpoint
304+ manager .MonitorEndpointResources (ga , endpoints )
305+
306+ // Verify watch was created since cross-namespace reference is allowed
307+ defaultManager , _ := manager .(* defaultEndpointResourcesManager )
308+ resourceKey := ktypes.NamespacedName {Namespace : svcNamespace , Name : svcName }
309+ assert .Contains (t , defaultManager .serviceWatches , resourceKey , "Cross-namespace service watch should be created when allowed" )
310+
311+ // Verify the watch has the right consumer
312+ watcher := defaultManager .serviceWatches [resourceKey ]
313+ assert .True (t , watcher .HasConsumer ("default/test-ga-allowed" ), "Watcher should have the GA as consumer" )
314+
315+ // Clean up
316+ gaKey := ktypes.NamespacedName {Namespace : "default" , Name : "test-ga-allowed" }
317+ manager .RemoveGA (gaKey )
318+
319+ // Verify watch was removed
320+ assert .NotContains (t , defaultManager .serviceWatches , resourceKey , "Cross-namespace service watch should be removed when GA is removed" )
321+ })
252322}
0 commit comments