Skip to content

Commit 9445e52

Browse files
dilyevskyclaude
andcommitted
[apiserver] deduplicate proxy replica status writes on xDS events
The event-driven path blindly appended replicas without checking for duplicates and always called Status().Update() even when nothing changed. This caused unnecessary resourceVersion bumps that triggered downstream reconciliation churn. Add duplicate detection before append and skip the write when no change occurred, matching the pattern already used by the 1-minute resync timer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 36a2ccf commit 9445e52

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

pkg/apiserver/controllers/proxy.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,38 @@ func (r *ProxyReconciler) run(ctx context.Context) {
224224
continue
225225
}
226226

227+
updated := false
227228
if !update.Delete {
228-
p.Status.Replicas = append(p.Status.Replicas, &corev1alpha2.ProxyReplicaStatus{
229-
Name: meta.Name,
230-
ConnectedAt: meta.ConnectedAt,
231-
Addresses: nodeMetadataToAddresses(meta),
232-
})
229+
// Check if replica already exists before appending.
230+
found := false
231+
for _, replica := range p.Status.Replicas {
232+
if replica.Name == meta.Name {
233+
found = true
234+
break
235+
}
236+
}
237+
if !found {
238+
p.Status.Replicas = append(p.Status.Replicas, &corev1alpha2.ProxyReplicaStatus{
239+
Name: meta.Name,
240+
ConnectedAt: meta.ConnectedAt,
241+
Addresses: nodeMetadataToAddresses(meta),
242+
})
243+
updated = true
244+
}
233245
} else {
234246
for i, replica := range p.Status.Replicas {
235247
if replica.Name == meta.Name {
236248
p.Status.Replicas = append(p.Status.Replicas[:i], p.Status.Replicas[i+1:]...)
249+
updated = true
237250
break
238251
}
239252
}
240253
}
241254

242-
if err := r.Status().Update(ctx, p); err != nil {
243-
slog.Error("Failed to update proxy status", "proxy", proxyName, "error", err)
255+
if updated {
256+
if err := r.Status().Update(ctx, p); err != nil {
257+
slog.Error("Failed to update proxy status", "proxy", proxyName, "error", err)
258+
}
244259
}
245260
}
246261

0 commit comments

Comments
 (0)