@@ -97,7 +97,7 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
97
97
log .Info ("apply changes to secondary pod" , "pod" , pod .Name )
98
98
99
99
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 )
101
101
continue
102
102
}
103
103
@@ -106,13 +106,46 @@ func (r *PerconaServerMySQLReconciler) smartUpdate(ctx context.Context, sts *app
106
106
107
107
log .Info ("apply changes to primary pod" , "pod" , primPod .Name )
108
108
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" )
112
142
return nil
113
143
}
114
144
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
+
116
149
}
117
150
118
151
func stsChanged (sts * appsv1.StatefulSet , pods []corev1.Pod ) bool {
0 commit comments