Skip to content

Commit 7a6020b

Browse files
committed
[feat aga] addressing feedback for refactoring
1 parent 0c62c7c commit 7a6020b

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

controllers/aga/globalaccelerator_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ func (r *globalAcceleratorReconciler) buildModel(ctx context.Context, ga *agaapi
269269
func (r *globalAcceleratorReconciler) reconcileGlobalAcceleratorResources(ctx context.Context, ga *agaapi.GlobalAccelerator) error {
270270
r.logger.Info("Reconciling GlobalAccelerator resources", "globalAccelerator", k8s.NamespacedName(ga))
271271

272-
// Get all endpoints from GA
273-
endpoints := aga.GetAllEndpointsFromGA(ga)
272+
// Get all desired endpoints from GA
273+
endpoints := aga.GetAllDesiredEndpointsFromGA(ga)
274274

275275
// Track referenced endpoints
276-
r.referenceTracker.UpdateReferencesForGA(ga, endpoints)
276+
r.referenceTracker.UpdateDesiredEndpointReferencesForGA(ga, endpoints)
277277

278278
// Update resource watches with the endpointResourcesManager
279279
r.endpointResourcesManager.MonitorEndpointResources(ga, endpoints)

pkg/aga/endpoint_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type EndpointReference struct {
2828
Endpoint *agaapi.GlobalAcceleratorEndpoint
2929
}
3030

31-
// GetAllEndpointsFromGA extracts all endpoint references from a GlobalAccelerator resource
32-
func GetAllEndpointsFromGA(ga *agaapi.GlobalAccelerator) []EndpointReference {
31+
// GetAllDesiredEndpointsFromGA extracts all endpoint references from a GlobalAccelerator resource
32+
func GetAllDesiredEndpointsFromGA(ga *agaapi.GlobalAccelerator) []EndpointReference {
3333
if ga == nil || ga.Spec.Listeners == nil {
3434
return nil
3535
}

pkg/aga/endpoint_utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func TestGetAllEndpointsFromGA(t *testing.T) {
180180
}
181181
}
182182

183-
result := GetAllEndpointsFromGA(tt.ga)
183+
result := GetAllDesiredEndpointsFromGA(tt.ga)
184184

185185
// Compare lengths
186186
assert.Equal(t, len(tt.expected), len(result))

pkg/aga/reference_tracker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func NewReferenceTracker(logger logr.Logger) *ReferenceTracker {
3434
}
3535
}
3636

37-
// UpdateReferencesForGA updates the tracking information for a GlobalAccelerator
38-
func (t *ReferenceTracker) UpdateReferencesForGA(ga *agaapi.GlobalAccelerator, endpoints []EndpointReference) {
37+
// UpdateDesiredEndpointReferencesForGA updates the tracking information for a GlobalAccelerator
38+
func (t *ReferenceTracker) UpdateDesiredEndpointReferencesForGA(ga *agaapi.GlobalAccelerator, desiredEndpoints []EndpointReference) {
3939
t.mutex.Lock()
4040
defer t.mutex.Unlock()
4141

@@ -45,7 +45,7 @@ func (t *ReferenceTracker) UpdateReferencesForGA(ga *agaapi.GlobalAccelerator, e
4545
currentResources := sets.New[ResourceKey]()
4646

4747
// Process each endpoint
48-
for _, endpoint := range endpoints {
48+
for _, endpoint := range desiredEndpoints {
4949
resourceKey := endpoint.ToResourceKey()
5050

5151
currentResources.Insert(resourceKey)

pkg/aga/reference_tracker_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ func TestReferenceTracker_UpdateReferencesForGA(t *testing.T) {
147147
// Create tracker
148148
tracker := NewReferenceTracker(logr.Discard())
149149

150-
endpoints := GetAllEndpointsFromGA(tt.ga)
150+
endpoints := GetAllDesiredEndpointsFromGA(tt.ga)
151151
// Update references
152-
tracker.UpdateReferencesForGA(tt.ga, endpoints)
152+
tracker.UpdateDesiredEndpointReferencesForGA(tt.ga, endpoints)
153153

154154
// Check number of tracked resources
155155
gaKey := types.NamespacedName{Namespace: tt.ga.Namespace, Name: tt.ga.Name}
@@ -212,8 +212,8 @@ func TestReferenceTracker_UpdateReferencesForGA_RemoveStaleReferences(t *testing
212212
// Create tracker and add initial references
213213
tracker := NewReferenceTracker(logr.Discard())
214214

215-
endpoints := GetAllEndpointsFromGA(ga)
216-
tracker.UpdateReferencesForGA(ga, endpoints)
215+
endpoints := GetAllDesiredEndpointsFromGA(ga)
216+
tracker.UpdateDesiredEndpointReferencesForGA(ga, endpoints)
217217

218218
// Verify initial state
219219
service1Key := ResourceKey{
@@ -256,8 +256,8 @@ func TestReferenceTracker_UpdateReferencesForGA_RemoveStaleReferences(t *testing
256256
}
257257

258258
// Update references with modified GA
259-
endpoints = GetAllEndpointsFromGA(ga)
260-
tracker.UpdateReferencesForGA(ga, endpoints)
259+
endpoints = GetAllDesiredEndpointsFromGA(ga)
260+
tracker.UpdateDesiredEndpointReferencesForGA(ga, endpoints)
261261

262262
// Verify that service1 is still referenced, service2 is no longer referenced, and service3 is now referenced
263263
assert.True(t, tracker.IsResourceReferenced(service1Key))
@@ -328,10 +328,10 @@ func TestReferenceTracker_RemoveGA(t *testing.T) {
328328

329329
// Create tracker and add references from both GAs
330330
tracker := NewReferenceTracker(logr.Discard())
331-
endpoints1 := GetAllEndpointsFromGA(ga1)
332-
endpoints2 := GetAllEndpointsFromGA(ga2)
333-
tracker.UpdateReferencesForGA(ga1, endpoints1)
334-
tracker.UpdateReferencesForGA(ga2, endpoints2)
331+
endpoints1 := GetAllDesiredEndpointsFromGA(ga1)
332+
endpoints2 := GetAllDesiredEndpointsFromGA(ga2)
333+
tracker.UpdateDesiredEndpointReferencesForGA(ga1, endpoints1)
334+
tracker.UpdateDesiredEndpointReferencesForGA(ga2, endpoints2)
335335

336336
// Resource keys
337337
service1Key := ResourceKey{
@@ -406,8 +406,8 @@ func TestReferenceTracker_IsResourceReferenced(t *testing.T) {
406406

407407
// Create tracker and add references
408408
tracker := NewReferenceTracker(logr.Discard())
409-
endpoints := GetAllEndpointsFromGA(ga)
410-
tracker.UpdateReferencesForGA(ga, endpoints)
409+
endpoints := GetAllDesiredEndpointsFromGA(ga)
410+
tracker.UpdateDesiredEndpointReferencesForGA(ga, endpoints)
411411

412412
// Resource keys - one that exists and one that doesn't
413413
existingResourceKey := ResourceKey{
@@ -479,10 +479,10 @@ func TestReferenceTracker_GetGAsForResource(t *testing.T) {
479479

480480
// Create tracker and add references
481481
tracker := NewReferenceTracker(logr.Discard())
482-
endpoints1 := GetAllEndpointsFromGA(ga1)
483-
endpoints2 := GetAllEndpointsFromGA(ga2)
484-
tracker.UpdateReferencesForGA(ga1, endpoints1)
485-
tracker.UpdateReferencesForGA(ga2, endpoints2)
482+
endpoints1 := GetAllDesiredEndpointsFromGA(ga1)
483+
endpoints2 := GetAllDesiredEndpointsFromGA(ga2)
484+
tracker.UpdateDesiredEndpointReferencesForGA(ga1, endpoints1)
485+
tracker.UpdateDesiredEndpointReferencesForGA(ga2, endpoints2)
486486

487487
// Resource key for the shared service
488488
sharedServiceKey := ResourceKey{

pkg/deploy/aga/listener_synthesizer.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ type resAndSDKListenerPair struct {
220220
// matchResAndSDKListeners matches resource listeners with SDK listeners using a multi-phase approach.
221221
//
222222
// The algorithm implements a two-phase matching process:
223-
// 1. First phase (Exact Matching): Matches listeners with identical protocol and port ranges
224-
// 2. Second phase (Similarity Matching): For remaining unmatched listeners, uses a similarity-based
225-
// algorithm to find the best matches based on protocol and port range overlap
223+
// 1. First phase (Exact Matching): Matches listeners with identical protocol and port ranges
224+
// 2. Second phase (Similarity Matching): For remaining unmatched listeners, uses a similarity-based
225+
// algorithm to find the best matches based on protocol and port range overlap
226226
//
227227
// Returns three groups:
228228
// - matchedResAndSDKListeners: pairs of resource and SDK listeners that will be updated
@@ -499,17 +499,17 @@ func (s *listenerSynthesizer) findConflictingAndNonConflictingListeners(
499499
// The scoring system uses these components:
500500
//
501501
// 1. Base Protocol Score:
502-
// - If protocols match: +40 points (significant bonus)
503-
// - If protocols don't match: 0 points (no bonus)
502+
// - If protocols match: +40 points (significant bonus)
503+
// - If protocols don't match: 0 points (no bonus)
504504
//
505505
// 2. Port Overlap Score:
506-
// - Uses Jaccard similarity: (intersection / union) * 100
507-
// - Calculates the percentage of common ports between the two listeners
508-
// - Converts port ranges into individual port sets for precise comparison
506+
// - Uses Jaccard similarity: (intersection / union) * 100
507+
// - Calculates the percentage of common ports between the two listeners
508+
// - Converts port ranges into individual port sets for precise comparison
509509
//
510510
// 3. Client Affinity Score:
511-
// - If both listeners have client affinity specified and they match: +10 points
512-
// - Otherwise: 0 points (no bonus)
511+
// - If both listeners have client affinity specified and they match: +10 points
512+
// - Otherwise: 0 points (no bonus)
513513
//
514514
// Note: In the future, we might need to add endpoint matching as well as one of the
515515
// score components so that we match the listeners with the most endpoint matches

0 commit comments

Comments
 (0)