@@ -2,6 +2,7 @@ package ps
2
2
3
3
import (
4
4
"context"
5
+ "k8s.io/apimachinery/pkg/util/wait"
5
6
"time"
6
7
7
8
"github.com/pkg/errors"
@@ -97,7 +98,7 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
97
98
log .Info ("apply changes to secondary pod" , "pod" , pod .Name )
98
99
99
100
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 )
101
102
continue
102
103
}
103
104
@@ -106,13 +107,42 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
106
107
107
108
log .Info ("apply changes to primary pod" , "pod" , primPod .Name )
108
109
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
+ }
112
134
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
113
140
}
114
141
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
+
116
146
}
117
147
118
148
func stsChanged (sts * appsv1.StatefulSet , pods []corev1.Pod ) bool {
0 commit comments