Skip to content

Commit a13687f

Browse files
authored
Merge pull request #677 from percona/K8SPS-307
K8SPS-307 fix smart update
2 parents 336f309 + 50b4e05 commit a13687f

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

pkg/controller/ps/upgrade.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ps
22

33
import (
44
"context"
5+
"k8s.io/apimachinery/pkg/util/wait"
56
"time"
67

78
"github.com/pkg/errors"
@@ -97,7 +98,7 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
9798
log.Info("apply changes to secondary pod", "pod", pod.Name)
9899

99100
if pod.ObjectMeta.Labels[controllerRevisionHash] == sts.Status.UpdateRevision {
100-
log.Info("pod updated updated", "pod", pod.Name)
101+
log.Info("pod updated", "pod", pod.Name)
101102
continue
102103
}
103104

@@ -106,13 +107,42 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
106107

107108
log.Info("apply changes to primary pod", "pod", primPod.Name)
108109

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")
110+
if primPod.ObjectMeta.Labels[controllerRevisionHash] != sts.Status.UpdateRevision {
111+
log.Info("primary pod was deleted", "pod", primPod.Name)
112+
err = deletePod(ctx, r.Client, primPod, currentSet)
113+
if err != nil {
114+
log.Info("primary pod deletion error", "pod", primPod.Name)
115+
return err
116+
}
117+
}
118+
119+
backoff := wait.Backoff{
120+
Steps: 5,
121+
Duration: 500 * time.Millisecond,
122+
Factor: 5.0,
123+
Jitter: 0.1,
124+
}
125+
err = k8sretry.OnError(backoff, func(err error) bool { return err != nil }, func() error {
126+
primPod, err := getMySQLPod(ctx, r.Client, cr, idx)
127+
if err != nil {
128+
return errors.Wrap(err, "get primary pod")
129+
}
130+
131+
if primPod.ObjectMeta.Labels[controllerRevisionHash] != sts.Status.UpdateRevision {
132+
return errors.New("primary pod controllerRevisionHash not equal sts.Status.UpdateRevision")
133+
}
112134
return nil
135+
})
136+
137+
if err != nil {
138+
log.Info("smart update of primary pod did not finish correctly after 5 retries")
139+
return err
113140
}
114141

115-
return deletePod(ctx, r.Client, primPod, currentSet)
142+
log.Info("primary pod updated", "pod", primPod.Name)
143+
log.Info("smart update finished")
144+
return nil
145+
116146
}
117147

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

0 commit comments

Comments
 (0)