Skip to content

Commit

Permalink
Only global resync when the replicas of the STS change (#3691)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
Co-authored-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
knative-prow-robot and pierDipi authored Feb 19, 2024
1 parent 28a2c2a commit fc6f83e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion control-plane/pkg/reconciler/consumergroup/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,32 @@ func ResyncOnStatefulSetChange(ctx context.Context, handle func(interface{})) {
ss := obj.(*appsv1.StatefulSet)
return ss.GetNamespace() == systemNamespace && kafkainternals.IsKnownStatefulSet(ss.GetName())
},
Handler: controller.HandleAll(handle),
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: handle,
UpdateFunc: func(oldObj, newObj interface{}) {
o, ok := oldObj.(*appsv1.StatefulSet)
if !ok {
return
}
n, ok := newObj.(*appsv1.StatefulSet)
if !ok {
return
}

// This should never happen, but we check for nil to be sure.
if o.Spec.Replicas == nil || n.Spec.Replicas == nil {
return
}

// Only handle when replicas change
if *o.Spec.Replicas == *n.Spec.Replicas && o.Status.ReadyReplicas == n.Status.ReadyReplicas {
return
}

handle(newObj)
},
DeleteFunc: handle,
},
})
}

Expand Down

0 comments on commit fc6f83e

Please sign in to comment.