Skip to content

Commit be634e1

Browse files
amuraruCopilot
andcommitted
perf(controllers): scope Cruise Control operation retrieval (#399)
perf(controllers): scope Cruise Control operation retrieval (#393) Use the cached cluster label only as a hint for an authoritative direct LIST. Fall back to the namespace LIST for missing or stale hints without adding direct GETs before conflict. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 33c4e13 commit be634e1

3 files changed

Lines changed: 511 additions & 3 deletions

File tree

‎controllers/cruisecontroloperation_controller.go‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ func (r *CruiseControlOperationReconciler) Reconcile(ctx context.Context, reques
8383
log := logr.FromContextOrDiscard(ctx)
8484
log.V(1).Info("reconciling CruiseControlOperation custom resources")
8585

86-
ccOperationListClusterWide := banzaiv1alpha1.CruiseControlOperationList{}
87-
err := r.DirectClient.List(ctx, &ccOperationListClusterWide, client.ListOption(client.InNamespace(request.Namespace)))
86+
ccOperationListClusterWide, err := r.listOperations(ctx, request.NamespacedName)
8887
if err != nil {
8988
return requeueWithError(log, err.Error(), err)
9089
}
@@ -251,6 +250,27 @@ func (r *CruiseControlOperationReconciler) Reconcile(ctx context.Context, reques
251250
return reconciled()
252251
}
253252

253+
func (r *CruiseControlOperationReconciler) listOperations(ctx context.Context, key client.ObjectKey) (banzaiv1alpha1.CruiseControlOperationList, error) {
254+
operations := banzaiv1alpha1.CruiseControlOperationList{}
255+
hint := &banzaiv1alpha1.CruiseControlOperation{}
256+
// The cache supplies only a selector hint; scheduling always uses the direct LIST.
257+
if err := r.Get(ctx, key, hint); err == nil && hint.GetClusterRef() != "" {
258+
if err := r.DirectClient.List(ctx, &operations, client.InNamespace(key.Namespace),
259+
client.MatchingLabels{banzaiv1beta1.KafkaCRLabelKey: hint.GetClusterRef()}); err != nil {
260+
return operations, err
261+
}
262+
for i := range operations.Items {
263+
if client.ObjectKeyFromObject(&operations.Items[i]) == key {
264+
return operations, nil
265+
}
266+
}
267+
}
268+
269+
operations = banzaiv1alpha1.CruiseControlOperationList{}
270+
err := r.DirectClient.List(ctx, &operations, client.InNamespace(key.Namespace))
271+
return operations, err
272+
}
273+
254274
func (r *CruiseControlOperationReconciler) persistExecutionResult(
255275
ctx context.Context,
256276
log logr.Logger,

0 commit comments

Comments
 (0)