Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator v1: fail status update if working on stale data #315

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions operator/pkg/resources/statefulset_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,15 @@ func (r *StatefulSetResource) handleScaling(ctx context.Context) error {
podName := fmt.Sprintf("%s-%d", r.LastObservedState.Name, targetOrdinal)
log.WithValues("pod", podName, "ordinal", targetOrdinal, "node_id", targetBroker).Info("start decommission broker")

err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
cluster := &vectorizedv1alpha1.Cluster{}
err := r.Get(ctx, types.NamespacedName{
Name: r.pandaCluster.Name,
Namespace: r.pandaCluster.Namespace,
}, cluster)
if err != nil {
return err
}
cluster.SetDecommissionBrokerID(targetBroker)
err = r.Status().Update(ctx, cluster)
if err == nil {
// sync original cluster variable to avoid conflicts on subsequent operations
r.pandaCluster.SetDecommissionBrokerID(targetBroker)
}
return err
})
if err != nil {
return err
r.pandaCluster.SetDecommissionBrokerID(targetBroker)
// Intentionally do not use retry-loop that is based on a fresh Get.
// If we did that, we'd not get a conflict error, if this Update is based on
// a stale status where currentReplicas is older than a previous patch that decreased it.
// Instead, send status update based on r.pandaCluster, so it fails if we're
// working based on an outdated status, and therefore outdated
// currentReplicas.
if err := r.Status().Update(ctx, r.pandaCluster); err != nil {
return fmt.Errorf("failed to update status with decommissionBrokerID=%d: %w", *targetBroker, err)
}

return nil
Expand Down