From b1a62c6b072bc4449dec9e5c48889ec96cde10bf Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 10 Oct 2023 12:02:33 +0200 Subject: [PATCH] misc: fix hypothetical implicit memory aliasing Signed-off-by: Hidde Beydals --- internal/controller/alert_controller.go | 4 ++-- internal/server/event_handlers.go | 10 +++++----- internal/server/receiver_handlers.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/controller/alert_controller.go b/internal/controller/alert_controller.go index 0616f232a..8e0c2cff5 100644 --- a/internal/controller/alert_controller.go +++ b/internal/controller/alert_controller.go @@ -206,8 +206,8 @@ func (r *AlertReconciler) requestsForProviderChange(ctx context.Context, o clien } var reqs []reconcile.Request - for _, i := range list.Items { - reqs = append(reqs, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(&i)}) + for i, _ := range list.Items { + reqs = append(reqs, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(&list.Items[i])}) } return reqs diff --git a/internal/server/event_handlers.go b/internal/server/event_handlers.go index b0a57227f..1cd1adee1 100644 --- a/internal/server/event_handlers.go +++ b/internal/server/event_handlers.go @@ -61,12 +61,12 @@ func (s *EventServer) handleEvent() func(w http.ResponseWriter, r *http.Request) // find matching alerts alerts := make([]apiv1beta2.Alert, 0) each_alert: - for _, alert := range allAlerts.Items { - alertLogger := eventLogger.WithValues("alert", client.ObjectKeyFromObject(&alert)) + for i, alert := range allAlerts.Items { + alertLogger := eventLogger.WithValues("alert", client.ObjectKeyFromObject(&allAlerts.Items[i])) ctx := log.IntoContext(ctx, alertLogger) // skip suspended and not ready alerts - isReady := conditions.IsReady(&alert) + isReady := conditions.IsReady(&allAlerts.Items[i]) if alert.Spec.Suspend || !isReady { continue each_alert } @@ -123,8 +123,8 @@ func (s *EventServer) handleEvent() func(w http.ResponseWriter, r *http.Request) eventLogger.Info(fmt.Sprintf("Dispatching event: %s", event.Message)) // dispatch notifications - for _, alert := range alerts { - alertLogger := eventLogger.WithValues("alert", client.ObjectKeyFromObject(&alert)) + for i, alert := range alerts { + alertLogger := eventLogger.WithValues("alert", client.ObjectKeyFromObject(&alerts[i])) ctx := log.IntoContext(ctx, alertLogger) // verify if event comes from a different namespace diff --git a/internal/server/receiver_handlers.go b/internal/server/receiver_handlers.go index c55d0063b..28688107d 100644 --- a/internal/server/receiver_handlers.go +++ b/internal/server/receiver_handlers.go @@ -408,8 +408,8 @@ func (s *ReceiverServer) requestReconciliation(ctx context.Context, logger logr. return nil } - for _, resource := range resources.Items { - if err := s.annotate(ctx, &resource); err != nil { + for i, resource := range resources.Items { + if err := s.annotate(ctx, &resources.Items[i]); err != nil { return fmt.Errorf("failed to annotate resource: '%s/%s.%s': %w", resource.Kind, resource.Name, namespace, err) } else { logger.Info(fmt.Sprintf("resource '%s/%s.%s' annotated",