Skip to content

Commit b8e3336

Browse files
committed
[feat aga] Add AGA listener deployer with clean up
1 parent b2d62b3 commit b8e3336

18 files changed

+3868
-95
lines changed

controllers/aga/globalaccelerator_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ func (r *globalAcceleratorReconciler) reconcileGlobalAcceleratorResources(ctx co
275275
func (r *globalAcceleratorReconciler) cleanupGlobalAcceleratorResources(ctx context.Context, ga *agaapi.GlobalAccelerator) error {
276276
r.logger.Info("Cleaning up GlobalAccelerator resources", "globalAccelerator", k8s.NamespacedName(ga))
277277

278-
// TODO we will handle cleaning up dependent resources when we implement those
278+
// Our enhanced AcceleratorManager now handles deletion of listeners before accelerator.
279+
// TODO: This will be enhanced to delete endpoint groups and endpoints
280+
// before deleting listeners and accelerator (when those features are implemented)
279281
// 1. Find the accelerator ARN from the CRD status
280282
if ga.Status.AcceleratorARN == nil {
281283
r.logger.Info("No accelerator ARN found in status, nothing to clean up", "globalAccelerator", k8s.NamespacedName(ga))

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"k8s.io/apimachinery/pkg/util/sets"
2323
"os"
24+
"sigs.k8s.io/aws-load-balancer-controller/pkg/aga"
2425
"sigs.k8s.io/aws-load-balancer-controller/pkg/shared_utils"
2526

2627
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
@@ -237,7 +238,7 @@ func main() {
237238
}
238239

239240
// Setup GlobalAccelerator controller only if enabled
240-
if shared_utils.IsAGAControllerEnabled(controllerCFG.FeatureGates, controllerCFG.AWSConfig.Region) {
241+
if aga.IsAGAControllerEnabled(controllerCFG.FeatureGates, controllerCFG.AWSConfig.Region) {
241242
agaReconciler := agacontroller.NewGlobalAcceleratorReconciler(mgr.GetClient(), mgr.GetEventRecorderFor("globalAccelerator"),
242243
finalizerManager, controllerCFG, cloud, ctrl.Log.WithName("controllers").WithName("globalAccelerator"), lbcMetricsCollector, reconcileCounters)
243244
if err := agaReconciler.SetupWithManager(ctx, mgr, clientSet); err != nil {
@@ -418,7 +419,7 @@ func main() {
418419
networkingwebhook.NewIngressValidator(mgr.GetClient(), controllerCFG.IngressConfig, ctrl.Log, lbcMetricsCollector).SetupWithManager(mgr)
419420

420421
// Setup GlobalAccelerator validator only if enabled
421-
if controllerCFG.FeatureGates.Enabled(config.AGAController) {
422+
if aga.IsAGAControllerEnabled(controllerCFG.FeatureGates, controllerCFG.AWSConfig.Region) {
422423
agawebhook.NewGlobalAcceleratorValidator(ctrl.Log, lbcMetricsCollector).SetupWithManager(mgr)
423424
}
424425
//+kubebuilder:scaffold:builder

pkg/shared_utils/aga_utils.go renamed to pkg/aga/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package shared_utils
1+
package aga
22

33
import (
44
"strings"

pkg/aga/utils_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package aga
2+
3+
import (
4+
"testing"
5+
6+
"sigs.k8s.io/aws-load-balancer-controller/pkg/config"
7+
)
8+
9+
func TestIsAGAControllerEnabled(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
featureGates config.FeatureGates
13+
region string
14+
want bool
15+
}{
16+
{
17+
name: "Feature gate disabled",
18+
featureGates: func() config.FeatureGates {
19+
fg := config.NewFeatureGates()
20+
fg.Disable(config.AGAController)
21+
return fg
22+
}(),
23+
region: "us-west-2",
24+
want: false,
25+
},
26+
{
27+
name: "Feature gate enabled, standard region",
28+
featureGates: func() config.FeatureGates {
29+
fg := config.NewFeatureGates()
30+
fg.Enable(config.AGAController)
31+
return fg
32+
}(),
33+
region: "us-west-2",
34+
want: true,
35+
},
36+
{
37+
name: "Feature gate enabled, China region",
38+
featureGates: func() config.FeatureGates {
39+
fg := config.NewFeatureGates()
40+
fg.Enable(config.AGAController)
41+
return fg
42+
}(),
43+
region: "cn-north-1",
44+
want: false,
45+
},
46+
{
47+
name: "Feature gate enabled, GovCloud region",
48+
featureGates: func() config.FeatureGates {
49+
fg := config.NewFeatureGates()
50+
fg.Enable(config.AGAController)
51+
return fg
52+
}(),
53+
region: "us-gov-west-1",
54+
want: false,
55+
},
56+
{
57+
name: "Feature gate enabled, ISO region",
58+
featureGates: func() config.FeatureGates {
59+
fg := config.NewFeatureGates()
60+
fg.Enable(config.AGAController)
61+
return fg
62+
}(),
63+
region: "us-iso-east-1",
64+
want: false,
65+
},
66+
{
67+
name: "Feature gate enabled, ISO-E region",
68+
featureGates: func() config.FeatureGates {
69+
fg := config.NewFeatureGates()
70+
fg.Enable(config.AGAController)
71+
return fg
72+
}(),
73+
region: "eu-isoe-west-1",
74+
want: false,
75+
},
76+
{
77+
name: "Feature gate enabled, upper case region",
78+
featureGates: func() config.FeatureGates {
79+
fg := config.NewFeatureGates()
80+
fg.Enable(config.AGAController)
81+
return fg
82+
}(),
83+
region: "US-WEST-2",
84+
want: true,
85+
},
86+
}
87+
88+
for _, tt := range tests {
89+
t.Run(tt.name, func(t *testing.T) {
90+
if got := IsAGAControllerEnabled(tt.featureGates, tt.region); got != tt.want {
91+
t.Errorf("IsAGAControllerEnabled() = %v, want %v", got, tt.want)
92+
}
93+
})
94+
}
95+
}

pkg/aws/services/globalaccelerator.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ type GlobalAccelerator interface {
2323
// DeleteAccelerator deletes an accelerator.
2424
DeleteAcceleratorWithContext(ctx context.Context, input *globalaccelerator.DeleteAcceleratorInput) (*globalaccelerator.DeleteAcceleratorOutput, error)
2525

26+
// CreateListener creates a new listener.
27+
CreateListenerWithContext(ctx context.Context, input *globalaccelerator.CreateListenerInput) (*globalaccelerator.CreateListenerOutput, error)
28+
29+
// DescribeListener describes a listener.
30+
DescribeListenerWithContext(ctx context.Context, input *globalaccelerator.DescribeListenerInput) (*globalaccelerator.DescribeListenerOutput, error)
31+
32+
// UpdateListener updates a listener.
33+
UpdateListenerWithContext(ctx context.Context, input *globalaccelerator.UpdateListenerInput) (*globalaccelerator.UpdateListenerOutput, error)
34+
35+
// DeleteListener deletes a listener.
36+
DeleteListenerWithContext(ctx context.Context, input *globalaccelerator.DeleteListenerInput) (*globalaccelerator.DeleteListenerOutput, error)
37+
38+
// wrapper to ListListeners API, which aggregates paged results into list.
39+
ListListenersAsList(ctx context.Context, input *globalaccelerator.ListListenersInput) ([]types.Listener, error)
40+
41+
// ListListenersForAccelerator lists all listeners for an accelerator.
42+
ListListenersForAcceleratorWithContext(ctx context.Context, input *globalaccelerator.ListListenersInput) (*globalaccelerator.ListListenersOutput, error)
43+
2644
// TagResource tags a resource.
2745
TagResourceWithContext(ctx context.Context, input *globalaccelerator.TagResourceInput) (*globalaccelerator.TagResourceOutput, error)
2846

@@ -117,3 +135,60 @@ func (c *defaultGlobalAccelerator) ListTagsForResourceWithContext(ctx context.Co
117135
}
118136
return client.ListTagsForResource(ctx, input)
119137
}
138+
139+
func (c *defaultGlobalAccelerator) CreateListenerWithContext(ctx context.Context, input *globalaccelerator.CreateListenerInput) (*globalaccelerator.CreateListenerOutput, error) {
140+
client, err := c.awsClientsProvider.GetGlobalAcceleratorClient(ctx, "CreateListener")
141+
if err != nil {
142+
return nil, err
143+
}
144+
return client.CreateListener(ctx, input)
145+
}
146+
147+
func (c *defaultGlobalAccelerator) DescribeListenerWithContext(ctx context.Context, input *globalaccelerator.DescribeListenerInput) (*globalaccelerator.DescribeListenerOutput, error) {
148+
client, err := c.awsClientsProvider.GetGlobalAcceleratorClient(ctx, "DescribeListener")
149+
if err != nil {
150+
return nil, err
151+
}
152+
return client.DescribeListener(ctx, input)
153+
}
154+
155+
func (c *defaultGlobalAccelerator) UpdateListenerWithContext(ctx context.Context, input *globalaccelerator.UpdateListenerInput) (*globalaccelerator.UpdateListenerOutput, error) {
156+
client, err := c.awsClientsProvider.GetGlobalAcceleratorClient(ctx, "UpdateListener")
157+
if err != nil {
158+
return nil, err
159+
}
160+
return client.UpdateListener(ctx, input)
161+
}
162+
163+
func (c *defaultGlobalAccelerator) DeleteListenerWithContext(ctx context.Context, input *globalaccelerator.DeleteListenerInput) (*globalaccelerator.DeleteListenerOutput, error) {
164+
client, err := c.awsClientsProvider.GetGlobalAcceleratorClient(ctx, "DeleteListener")
165+
if err != nil {
166+
return nil, err
167+
}
168+
return client.DeleteListener(ctx, input)
169+
}
170+
171+
func (c *defaultGlobalAccelerator) ListListenersForAcceleratorWithContext(ctx context.Context, input *globalaccelerator.ListListenersInput) (*globalaccelerator.ListListenersOutput, error) {
172+
client, err := c.awsClientsProvider.GetGlobalAcceleratorClient(ctx, "ListListeners")
173+
if err != nil {
174+
return nil, err
175+
}
176+
return client.ListListeners(ctx, input)
177+
}
178+
179+
func (c *defaultGlobalAccelerator) ListListenersAsList(ctx context.Context, input *globalaccelerator.ListListenersInput) ([]types.Listener, error) {
180+
var result []types.Listener
181+
client, err := c.awsClientsProvider.GetGlobalAcceleratorClient(ctx, "ListListeners")
182+
if err != nil {
183+
return nil, err
184+
}
185+
paginator := globalaccelerator.NewListListenersPaginator(client, input)
186+
for paginator.HasMorePages() {
187+
output, err := paginator.NextPage(ctx)
188+
if err != nil {
189+
return nil, err
190+
}
191+
result = append(result, output.Listeners...)
192+
}
193+
return result, nil
194+
}

pkg/aws/services/globalaccelerator_mocks.go

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)