Skip to content

Commit 230839a

Browse files
committed
[feat aga] few bugfixes and code refactoring
1 parent d278541 commit 230839a

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

controllers/aga/globalaccelerator_controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ const (
6868
requeueMessage = "Monitoring provisioning state"
6969
statusUpdateRequeueTime = 1 * time.Minute
7070

71-
// Status reason constants
72-
EndpointLoadFailed = "EndpointLoadFailed"
73-
7471
// Metric stage constants
7572
MetricStageFetchGlobalAccelerator = "fetch_globalAccelerator"
7673
MetricStageAddFinalizers = "add_finalizers"
@@ -90,7 +87,7 @@ const (
9087
func NewGlobalAcceleratorReconciler(k8sClient client.Client, eventRecorder record.EventRecorder, finalizerManager k8s.FinalizerManager, config config.ControllerConfig, cloud services.Cloud, logger logr.Logger, metricsCollector lbcmetrics.MetricCollector, reconcileCounters *metricsutil.ReconcileCounters) *globalAcceleratorReconciler {
9188

9289
// Create tracking provider
93-
trackingProvider := tracking.NewDefaultProvider(agaTagPrefix, config.ClusterName, tracking.WithRegion(config.AWSConfig.Region))
90+
trackingProvider := tracking.NewDefaultProvider(agaTagPrefix, config.ClusterName, tracking.WithRegion(cloud.Region()))
9491

9592
// Create model builder
9693
agaModelBuilder := aga.NewDefaultModelBuilder(
@@ -99,7 +96,7 @@ func NewGlobalAcceleratorReconciler(k8sClient client.Client, eventRecorder recor
9996
trackingProvider,
10097
config.FeatureGates,
10198
config.ClusterName,
102-
config.AWSConfig.Region,
99+
cloud.Region(),
103100
config.DefaultTags,
104101
config.ExternalManagedTags,
105102
logger.WithName("aga-model-builder"),
@@ -288,7 +285,7 @@ func (r *globalAcceleratorReconciler) reconcileGlobalAcceleratorResources(ctx co
288285
r.logger.Error(err, "Fatal error loading endpoints")
289286

290287
// Handle other endpoint loading errors
291-
if statusErr := r.statusUpdater.UpdateStatusFailure(ctx, ga, EndpointLoadFailed, err.Error()); statusErr != nil {
288+
if statusErr := r.statusUpdater.UpdateStatusFailure(ctx, ga, agadeploy.EndpointLoadFailed, err.Error()); statusErr != nil {
292289
r.logger.Error(statusErr, "Failed to update GlobalAccelerator status after endpoint load failure")
293290
}
294291
return err
@@ -302,6 +299,8 @@ func (r *globalAcceleratorReconciler) reconcileGlobalAcceleratorResources(ctx co
302299
}
303300
r.metricsCollector.ObserveControllerReconcileLatency(controllerName, MetricStageBuildModel, buildModelFn)
304301
if err != nil {
302+
r.eventRecorder.Event(ga, corev1.EventTypeWarning, k8s.GatewayEventReasonFailedBuildModel, fmt.Sprintf("Failed to build model: %v", err))
303+
r.logger.Error(err, fmt.Sprintf("Failed to build model for: %v", k8s.NamespacedName(ga)))
305304
// Update status to indicate model building failure
306305
if statusErr := r.statusUpdater.UpdateStatusFailure(ctx, ga, agadeploy.ModelBuildFailed, fmt.Sprintf("Failed to build model: %v", err)); statusErr != nil {
307306
r.logger.Error(statusErr, "Failed to update GlobalAccelerator status after model build failure")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/golang/mock v1.6.0
2626
github.com/google/go-cmp v0.7.0
2727
github.com/google/uuid v1.6.0
28+
github.com/hashicorp/golang-lru v1.0.2
2829
github.com/onsi/ginkgo/v2 v2.23.3
2930
github.com/onsi/gomega v1.37.0
3031
github.com/pkg/errors v0.9.1
@@ -104,7 +105,6 @@ require (
104105
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
105106
github.com/hashicorp/errwrap v1.1.0 // indirect
106107
github.com/hashicorp/go-multierror v1.1.1 // indirect
107-
github.com/hashicorp/golang-lru v1.0.2 // indirect
108108
github.com/huandu/xstrings v1.5.0 // indirect
109109
github.com/imkira/go-interpol v1.1.0 // indirect
110110
github.com/inconshreveable/mousetrap v1.1.0 // indirect

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func main() {
241241
}
242242

243243
// Setup GlobalAccelerator controller only if enabled
244-
if aga.IsAGAControllerEnabled(controllerCFG.FeatureGates, controllerCFG.AWSConfig.Region) {
244+
if aga.IsAGAControllerEnabled(controllerCFG.FeatureGates, cloud.Region()) {
245245
agaReconciler := agacontroller.NewGlobalAcceleratorReconciler(mgr.GetClient(), mgr.GetEventRecorderFor("globalAccelerator"),
246246
finalizerManager, controllerCFG, cloud, ctrl.Log.WithName("controllers").WithName("globalAccelerator"), lbcMetricsCollector, reconcileCounters)
247247
if err := agaReconciler.SetupWithManager(ctx, mgr, clientSet); err != nil {
@@ -442,7 +442,7 @@ func main() {
442442
networkingwebhook.NewIngressValidator(mgr.GetClient(), controllerCFG.IngressConfig, ctrl.Log, lbcMetricsCollector).SetupWithManager(mgr)
443443

444444
// Setup GlobalAccelerator validator only if enabled
445-
if aga.IsAGAControllerEnabled(controllerCFG.FeatureGates, controllerCFG.AWSConfig.Region) {
445+
if aga.IsAGAControllerEnabled(controllerCFG.FeatureGates, cloud.Region()) {
446446
agawebhook.NewGlobalAcceleratorValidator(ctrl.Log, lbcMetricsCollector).SetupWithManager(mgr)
447447
}
448448
//+kubebuilder:scaffold:builder

pkg/deploy/aga/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const (
99

1010
// DeploymentFailed is the error code when stack deployment fails
1111
DeploymentFailed = "DeploymentFailed"
12+
13+
// Status reason constants
14+
EndpointLoadFailed = "EndpointLoadFailed"
1215
)
1316

1417
// AcceleratorNotDisabledError is returned when an accelerator is not ready for deletion

pkg/k8s/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
GlobalAcceleratorEventReasonFailedUpdateStatus = "FailedUpdateStatus"
5353
GlobalAcceleratorEventReasonFailedCleanup = "FailedCleanup"
5454
GlobalAcceleratorEventReasonFailedBuildModel = "FailedBuildModel"
55+
GlobalAcceleratorEventReasonFailedEndpointLoad = "FailedEndpointLoad"
5556
GlobalAcceleratorEventReasonFailedDeploy = "FailedDeploy"
5657
GlobalAcceleratorEventReasonSuccessfullyReconciled = "SuccessfullyReconciled"
5758
)

pkg/status/aga/status_updater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (u *defaultStatusUpdater) UpdateStatusFailure(ctx context.Context, ga *v1be
188188
Status: metav1.ConditionFalse,
189189
LastTransitionTime: metav1.Now(),
190190
Reason: reason,
191-
Message: message,
191+
Message: "Reconciliation failed. See events and controller logs for details",
192192
}
193193

194194
conditionUpdated := u.updateCondition(&ga.Status.Conditions, failureCondition)

0 commit comments

Comments
 (0)