Skip to content

Commit aaf5bf0

Browse files
committed
fix: use proper context instead of context.TODO()
Replace context.TODO() with the proper context parameter in three locations: - pkg/resources/kafka/kafka.go: reconcileKafkaPodDelete() now uses ctx for List() and CruiseControlScalerFactory() - internal/alertmanager/currentalert/process.go: downScale() now uses ctx for NewCruiseControlScaler() This fix enables: - Proper cancellation propagation when operations need to be stopped - Better observability (tracing, logging) through context values - Prevention of potential resource leaks from uncancelable operations Resolves FIXME comments in both files.
1 parent 18343d8 commit aaf5bf0

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

internal/alertmanager/currentalert/process.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ func downScale(ctx context.Context, log logr.Logger, labels model.LabelSet, clie
322322
brokerID = string(broker)
323323
} else {
324324
cruiseControlURL := scale.CruiseControlURLFromKafkaCluster(cr)
325-
// FIXME: we should reuse the context of passed to AController.Start() here
326-
cc, err := scale.NewCruiseControlScaler(context.TODO(), cruiseControlURL)
325+
cc, err := scale.NewCruiseControlScaler(ctx, cruiseControlURL)
327326
if err != nil {
328327
return errors.WrapIfWithDetails(err, "failed to initialize Cruise Control Scaler",
329328
"cruise control url", cruiseControlURL)

pkg/resources/kafka/kafka.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (r *Reconciler) Reconcile(log logr.Logger) error {
505505

506506
func (r *Reconciler) reconcileKafkaPodDelete(ctx context.Context, log logr.Logger) error {
507507
podList := &corev1.PodList{}
508-
err := r.List(context.TODO(), podList,
508+
err := r.List(ctx, podList,
509509
client.InNamespace(r.KafkaCluster.Namespace),
510510
client.MatchingLabels(apiutil.LabelsForKafka(r.KafkaCluster.Name)),
511511
)
@@ -533,8 +533,7 @@ func (r *Reconciler) reconcileKafkaPodDelete(ctx context.Context, log logr.Logge
533533

534534
if len(podsDeletedFromSpec) > 0 {
535535
if !arePodsAlreadyDeleted(podsDeletedFromSpec, log) {
536-
// FIXME: we should reuse the context of the Kafka Controller
537-
cc, err := r.CruiseControlScalerFactory(context.TODO(), r.KafkaCluster)
536+
cc, err := r.CruiseControlScalerFactory(ctx, r.KafkaCluster)
538537
if err != nil {
539538
return errorfactory.New(errorfactory.CruiseControlNotReady{}, err,
540539
"failed to initialize Cruise Control Scaler", "cruise control url", scale.CruiseControlURLFromKafkaCluster(r.KafkaCluster))

0 commit comments

Comments
 (0)