Skip to content

Commit 5f8a479

Browse files
committed
K8SPS-307 fix smart update
1 parent 4fd644f commit 5f8a479

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

pkg/controller/ps/upgrade.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
9797
log.Info("apply changes to secondary pod", "pod", pod.Name)
9898

9999
if pod.ObjectMeta.Labels[controllerRevisionHash] == sts.Status.UpdateRevision {
100-
log.Info("pod updated updated", "pod", pod.Name)
100+
log.Info("pod updated", "pod", pod.Name)
101101
continue
102102
}
103103

@@ -106,13 +106,46 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
106106

107107
log.Info("apply changes to primary pod", "pod", primPod.Name)
108108

109-
if primPod.ObjectMeta.Labels[controllerRevisionHash] == sts.Status.UpdateRevision {
110-
log.Info("primary pod updated updated", "primPod name", primPod.Name)
111-
log.Info("smart update finished")
109+
if primPod.ObjectMeta.Labels[controllerRevisionHash] != sts.Status.UpdateRevision {
110+
log.Info("primary pod was deleted", "pod", primPod.Name)
111+
err = deletePod(ctx, r.Client, primPod, currentSet)
112+
113+
if err != nil {
114+
log.Info("primary pod deletion error", "pod", primPod.Name)
115+
return err
116+
}
117+
}
118+
119+
retriable := func(err error) bool {
120+
return err != nil
121+
}
122+
123+
retry := k8sretry.DefaultRetry
124+
retry.Duration = 5 * time.Second
125+
retry.Steps = 10
126+
127+
err = k8sretry.OnError(retry, retriable, func() error {
128+
129+
primPod, err := getMySQLPod(ctx, r.Client, cr, idx)
130+
if err != nil {
131+
return errors.Wrap(err, "get primary pod")
132+
}
133+
134+
if primPod.ObjectMeta.Labels[controllerRevisionHash] != sts.Status.UpdateRevision {
135+
return errors.New("primary pod controllerRevisionHash not equal sts.Status.UpdateRevision")
136+
}
137+
return nil
138+
})
139+
140+
if err != nil {
141+
log.Info("smart update of primary pod did not finish correctly after 10 retries")
112142
return nil
113143
}
114144

115-
return deletePod(ctx, r.Client, primPod, currentSet)
145+
log.Info("primary pod updated", "primPod name", primPod.Name)
146+
log.Info("smart update finished")
147+
return nil
148+
116149
}
117150

118151
func stsChanged(sts *appsv1.StatefulSet, pods []corev1.Pod) bool {

0 commit comments

Comments
 (0)