Skip to content

Commit b47c1fb

Browse files
committed
[feat aga] Add e2e tests for cross namepsace support for AGA
1 parent 052917d commit b47c1fb

File tree

9 files changed

+1323
-88
lines changed

9 files changed

+1323
-88
lines changed

pkg/aga/endpoint_resources_manager_test.go

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

test/e2e/gateway/auxillary_stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (s *auxiliaryResourceStack) CreateReferenceGrants(ctx context.Context, f *f
101101
}
102102
s.refGrants = refGrants
103103

104-
if err := createReferenceGrants(ctx, f, s.refGrants); err != nil {
104+
if err := CreateReferenceGrants(ctx, f, s.refGrants); err != nil {
105105
return err
106106
}
107107

test/e2e/gateway/common_resource_stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func createServices(ctx context.Context, f *framework.Framework, svcs []*corev1.
181181
return nil
182182
}
183183

184-
func createReferenceGrants(ctx context.Context, f *framework.Framework, refGrants []*gwbeta1.ReferenceGrant) error {
184+
func CreateReferenceGrants(ctx context.Context, f *framework.Framework, refGrants []*gwbeta1.ReferenceGrant) error {
185185
f.Logger.Info("About to create ref grant")
186186
for _, refg := range refGrants {
187187
f.Logger.Info("creating ref grant", "refg", k8s.NamespacedName(refg))

test/e2e/gateway/nlb_test_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func (s *NLBTestStack) CreateFENLBReferenceGrant(ctx context.Context, f *framewo
374374
},
375375
}
376376

377-
if err := createReferenceGrants(ctx, f, []*gwbeta1.ReferenceGrant{refGrant}); err != nil {
377+
if err := CreateReferenceGrants(ctx, f, []*gwbeta1.ReferenceGrant{refGrant}); err != nil {
378378
return nil, err
379379
}
380380

test/e2e/globalaccelerator/aga_verifier.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func verifyGlobalAcceleratorConfiguration(ctx context.Context, f *framework.Fram
157157
for k, expectedEG := range expectedListener.EndpointGroups {
158158
eg := listEGResp[k]
159159

160+
if len(eg.EndpointDescriptions) != expectedEG.NumEndpoints {
161+
return fmt.Errorf("listener[%d] endpoint group[%d] endpoint count mismatch: expected %d, got %d", i, k, expectedEG.NumEndpoints, len(eg.EndpointDescriptions))
162+
}
163+
160164
if expectedEG.TrafficDialPercentage > 0 && awssdk.ToFloat32(eg.TrafficDialPercentage) != float32(expectedEG.TrafficDialPercentage) {
161165
return fmt.Errorf("listener[%d] endpoint group[%d] traffic dial percentage mismatch: expected %d, got %f", i, k, expectedEG.TrafficDialPercentage, awssdk.ToFloat32(eg.TrafficDialPercentage))
162166
}
@@ -174,10 +178,6 @@ func verifyGlobalAcceleratorConfiguration(ctx context.Context, f *framework.Fram
174178
}
175179
}
176180
}
177-
178-
if expectedEG.NumEndpoints > 0 && len(eg.EndpointDescriptions) != expectedEG.NumEndpoints {
179-
return fmt.Errorf("listener[%d] endpoint group[%d] endpoint count mismatch: expected %d, got %d", i, k, expectedEG.NumEndpoints, len(eg.EndpointDescriptions))
180-
}
181181
}
182182
}
183183
}

0 commit comments

Comments
 (0)